HATEOAS(Hypermedia as the engine of application state)
You will build a hypermedia-driven REST service with Spring HATEOAS: a library of APIs that you can use to create links that point to Spring MVC controllers, build up resource representations, and control how they are rendered into supported hypermedia formats (such as HAL).
HAL이 좀 더 궁금하다면? 클릭
Hypertext Application Language
HAL is a simple format that gives a consistent and easy way to hyperlink between resources in your API.
application/hal+json
{
"_links": {
"self": { "href": "/orders" },
"curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true }],
"next": { "href": "/orders?page=2" },
"ea:find": {
"href": "/orders{?id}",
"templated": true
},
"ea:admin": [{
"href": "/admins/2",
"title": "Fred"
}, {
"href": "/admins/5",
"title": "Kate"
}]
},
"currentlyProcessing": 14,
"shippedToday": 20,
"_embedded": {
"ea:order": [{
"_links": {
"self": { "href": "/orders/123" },
"ea:basket": { "href": "/baskets/98712" },
"ea:customer": { "href": "/customers/7809" }
},
"total": 30.00,
"currency": "USD",
"status": "shipped"
}, {
"_links": {
"self": { "href": "/orders/124" },
"ea:basket": { "href": "/baskets/97213" },
"ea:customer": { "href": "/customers/12369" }
},
"total": 20.00,
"currency": "USD",
"status": "processing"
}]
}
}
The service will accept HTTP GET requests at http://localhost:8080/greeting.
It will respond with a JSON representation of a greeting that is enriched with the simplest possible hypermedia element, a link that points to the resource itself. The following listing shows the output:
{
"content":"Hello, World!",
"_links":{
"self":{
"href":"http://localhost:8080/greeting?name=World"
}
}
}
제대로된 REST api를 구현하기 위해서 HATEOAS(헤이티오스)라는 spring에서 제공하는
https://spring.io/guides/gs/rest-hateoas/ 것을 사용해 링크와 리소스를 만듭니다.
'OpenSource > Spring Boot' 카테고리의 다른 글
springboot error - Could not write JSON: Can not start an array, expecting field name (context: Object) (0) | 2022.03.25 |
---|---|
Spring Rest Docs 사용하기 (0) | 2022.03.22 |
springbootStudy06- lombok 을 사용해보자! (0) | 2021.11.09 |
springbootStudy05- test code를 작성해보자 (0) | 2021.10.27 |
springbootStudy04 - .gitignore 파일을 만들어보자 (0) | 2021.10.26 |