The jsonapi spec is a very clean and elegant way to make requests and decode responses for an application that provides and API. And as far as I can see is one of the best implementations of the HATEOAS principle.
The only thing lacking, in my opinion, is that although you can now in theory traverse an entire api based on the links provided in a response, there is no way of knowing how you can manipulate those resources, other than brute forcing to a resource url, trying different combinations of HTTP verbs and attributes.
The HTTP/1.1 specification section 9.2 page 51, describe the OPTIONS
method, and in part states that when a request using the OPTIONS
method on a specific resource is made:
The response body, if any, SHOULD also include information about the communication options
I propose that we make a standard jsonapi response to an OPTIONS method request.
As a first pass something along the lines of adding a new top level key, called options
with the following structure:
{
"options": [
{
"type" : "articles",
"method": "POST",
"attributes": {
"body": "string",
"author": "string"
}
},
{
"type": "articles",
"method" : "PUT",
"attributes": {
"body": "string"
}
}
]
}
The above is just an example, that serve to illustrate that when creating an article you have to provide both a author and a body, but when updating an article you cannot change the author.
JSON Shema might be the best tool for describing the format of the content inside the attributes key, as it can give type, occurrences along with human readable descriptions.
Please provide your thoughts and concerns?