Reputation: 1397
I have an extremely simple RESTful service that receives some form data via POST, it's purpose of which is to simply retain the body of text (with a unique id) in cloud storage (Amazon S3, Azure Blob Storage, etc.) as a file...
So, question is.. if everything is good, and i return a 200 response to the caller, what should i return to the caller in terms of a body?
Anything? Nothing?
If this were creating a database record.. perhaps the id of that new record might be useful.. but in this instance, i'm thinking simply the HttpRepsone code is sufficient?
Anyone agree, disagree, or have a supporting link with discussion?
I should add that the requests to this service are pretty much.. hand off, and go.. they don't actually need the unique id that i am proposing to send back.. this is more for "completeness".
Upvotes: 4
Views: 10573
Reputation: 130877
Once you are creating a resource on the server, you should return the 201
status code along with a Location
header, allowing the client to locate the newly created resource.
The response payload is optional and it typically describes and links to the resource created.
See the following quote from the RFC 7231:
[...] If one or more resources has been created on the origin server as a result of successfully processing a
POST
request, the origin server SHOULD send a201
(Created) response containing aLocation
header field that provides an identifier for the primary resource created and a representation that describes the status of the request while referring to the new resource(s). [...]
Also from the RFC 7231:
The
201
(Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either aLocation
header field in the response or, if noLocation
field is received, by the effective request URI.The
201
response payload typically describes and links to the resource(s) created. [...]
The
Location
header field is used in some responses to refer to a specific resource in relation to the response. The type of relationship is defined by the combination of request method and status code semantics.Location = URI-reference
The field value consists of a single URI-reference. [...] For
201
(Created) responses, theLocation
value refers to the primary resource created by the request. [...]
Upvotes: 8
Reputation: 1021
I should add that the requests to this service are pretty much.. hand off, and go.. they don't actually need the unique id
Its absolutely fine to return nothing in response to a post request. You are saying it's not even required by the caller. But the status code 201 will make more sense.
Upvotes: 1