I have started designing an API and have decided to have a go at making it conform to REST/HATEOAS. What should the entry point for the API be?
It seems like a common one is GET /
but from what I've read it might make more sense logically to use OPTIONS /
, as there isn't actually a resource at /
for retrieving.
I've given examples of both here, using HAL syntax for JSON as a hypermedia format.
GET /
Request:
GET / HTTP/1.1
Host: example.com
Response:
HTTP/1.1 200 OK
Date: …
Content-Type: application/json;charset=utf-8
Content-Length: 143
{
"_links": {
"self": {
"href": "/"
},
"penguins": {
"href": "/penguins"
}
}
}
OPTIONS /
Request:
OPTIONS / HTTP/1.1
Host: example.com
Response:
HTTP/1.1 200 OK
Date: …
Allow: OPTIONS
Content-Type: application/json;charset=utf-8
Content-Length: 143
{
"_links": {
"self": {
"href": "/"
},
"penguins": {
"href": "/penguins"
}
}
}
/
doesn't point to a resource? In REST, all URLs refer to resources. In this case, it's a resource to the menu of available links you can follow. – Parma