It's a good practice to let a client specify the format in Web REST API:
GET /api/items/123.csv
However, not only GET
can return some answer, but POST
also can do
Status: 201 Created
{
mgs: "Your item has created successfully",
href: "/example.com/items/123"
}
How should URI
look like for a POST
(PUT
or whatever, but not GET
) request which returns a response so that a client can specify the format they want the response to be in? Like this?:
POST /api/items/.csv
Or suppose there is an error when a client sends a POST request and the server must inform the client about it:
Status: 400 Bad Request
{
mgs: "this is a bad request",
devMessage: "it's bad because ...."
friendlyMessage: "something bad happened..."
}
What format should it respond in, why and how do I specify it as a client?
P.S. - I'm aware about REST - Tradeoffs between content negotiation via Accept header versus extensions
Accept
header, especially when returning an error and not a 200, but it should definitely try to get anyContent-Type
it sends back to actually describe what it is sending.