Fowler describes Hypermedia Controls as the last word step to reaching the glory of REST. It’s these days referred to as HATEOAS:
With HATEOAS, a shopper interacts with a community software whose software servers present info dynamically by means of hypermedia. A REST shopper wants little to no prior data about how you can work together with an software or server past a generic understanding of hypermedia.
HATEOAS is an idea; right here’s a attainable implementation taken from Wikipedia. When one requests a checking account, say /accounts/a1b2c3d4e5f6
, the response accommodates hyperlinks to actions attainable with this particular checking account:
{
"account": {
"account_number": "a1b2c3d4e5f6",
"stability": {
"foreign money": "USD",
"worth": 100.00
},
"hyperlinks": {
"_self": "/accounts/a1b2c3d4e5f6",
"deposit": "/accounts/a1b2c3d4e5f6:deposit",
"withdrawal": "/accounts/a1b2c3d4e5f6:withdrawal",
"switch": "/accounts/a1b2c3d4e5f6:switch",
"close-request": "/accounts/a1b2c3d4e5f6:close-request"
}
}
}
If the stability is destructive, solely the deposit hyperlink will likely be accessible:
{
"account": {
"account_number": "a1b2c3d4e5f6",
"stability": {
"foreign money": "USD",
"worth": 100.00
},
"hyperlinks": {
"_self": "/accounts/a1b2c3d4e5f6",
"deposit": "/accounts/a1b2c3d4e5f6:deposit",
}
}
}
A typical challenge with REST is the shortage of requirements; HATEOAS is not any totally different. The primary try to carry a point of standardization was the JSON Hypertext Utility Language, aka HAL. Be aware that it was incepted in 2012; the most recent model dates from 2016, and it’s nonetheless in draft.
Right here’s a fast diagram that summarizes the proposal:
We will rework the above with HAL as the next:
GET /accounts/a1b2c3d4e5f6 HTTP/1.1
Settle for: software/hal+json
HTTP/1.1 200 OK
Content material-Sort: software/hal+json
{
"account": {
"account_number": "a1b2c3d4e5f6",
"stability": {
"foreign money": "USD",
"worth": 100.00
},
"_links": { (1)
"self": { (2)
"href" : "/accounts/a1b2c3d4e5f6",
"strategies": ["GET"] (3)
},
"deposit": {
"href" : "/accounts/a1b2c3d4e5f6:deposit", (4)
"strategies": ["POST"] (3)
}
}
}
}
1 | Out there hyperlinks |
2 | Hyperlink to self |
3 | Inform which HTTP verb can be utilized |
4 | Hyperlink to deposit |
One other try at standardization is RFC 8288, aka Net Linking. It describes the format and accommodates a hyperlink relationship registry, e.g., alternate
and copyright
. Essentially the most important distinction with HAL is that RFC 8288 communicates hyperlinks by way of HTTP response headers.
HTTP/2 200 OK
Hyperlink: </accounts/a1b2c3d4e5f6> rel="self";
technique="GET", (1)
</accounts/a1b2c3d4e5f6:deposit> rel="https://my.financial institution/deposit";
title="Deposit";
technique="POST" (2)
{
"account": {
"account_number": "a1b2c3d4e5f6",
"stability": {
"foreign money": "USD",
"worth": 100.00
}
}
}
1 | Hyperlink to the present useful resource with the non-standard self relation sort |
2 | Hyperlink to deposit with the extension https://my.financial institution/deposit relation sort and an arbitrary title goal attribute |
Different various media varieties specs can be found.
Title | Description | Offered by |
---|---|---|
|
People |
|
|
Particular person |
|
|
People |
|
|
Particular person |
|
|
IETF |