Is there a "REST-way" by which a client of a REST-API can indicate whether it is interested in getting a resource representation of the created resource in the POST response or whether it is just interested in HTTP response code (i.e. 201 on success) and location header?
I was thinking on using the Accept header. If the client adds a media type to this header that is supported by the API, the representation will be returned. Otherwise, it will just get a HTTP Created and the location header.
Context: The API will have to types of clients. A Web-UI client, that wants the representation in the response to save a network round-trip. And backend-service clients that will create resources at high rate in fire-and-forget manner. They're only interested in response code and resource URI.
There is a HTTP header:
Prefer: return=representation
The server can signal that it respected the header by returning:
Preference-Applied: return=representation
https://www.rfc-editor.org/rfc/rfc7240
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With