Handling content negotiation
The same HTTP POST endpoints can process the JSON content as well as the URL-encoded content; however, GET endpoints, which previously returned JSON content, now only return HTML content. Is it possible to return both the JSON and HTML content from the same GET endpoints (similarly to what has been done for POST endpoints)?
The answer is yes, and this HTTP feature is named content negotiation. The word negotiation comes from the fact that HTTP clients inform servers of which versions of a resource they would rather get (according to their capabilities). They do this by specifying HTTP request headers starting with Accept
. For instance, your web browser usually sends, along with each request, an Accept-Language
header containing your preferred languages. This gives the server the opportunity to return a version of the document in a language that fits best your preferences. The same applies to the result content types, which are driven by the Accept
header. For...