This MDN article here summarises quite well the technique of Content Negotiation on a REST API.
In essence, if we have a GET /student/:id
endpoint, we might want to see different representations of that resource, (html, pdf, json, xml), and we can do this by attaching an Accept
header to the resource.
They are all the same resource though - they're different representations of the same resource.
My question is - as a consumer of an API, it's very useful for me to have a JSON Schema that describes a resource.
Is it appropriate that one of the representations of a resource be that JSON schema? It would mean that GET /student/1
and GET /student/2
should always return the same result for example.
What's a tidier alternative?
Accept: application/schema+json
and you get a schema? Not a bad idea in practical terms.