Joe Nelson
Joe Nelson

Reputation: 549

Including created resource in HTTP POST response?

RFC7231 says a server should respond to a resource-creating POST request with status 201 and a Location header to the new resource. In some situations it could be convenient for the server to include a representation of the created resource in its response, but in other cases this would be a waste of bandwidth.

Might this be a good place for content negotiation within the post request? If so, what request headers should be sent to indicate that the client would like the resource returned in addition to the Location header?

Upvotes: 4

Views: 433

Answers (1)

Jørn Wildt
Jørn Wildt

Reputation: 4482

I would suggest using the "Prefer" header:

Request:

PUT /xxx
Prefer: return=representation

Response:

201 Created

{ ... created resource representation ... }

See https://www.rfc-editor.org/rfc/rfc7240

Upvotes: 4

Related Questions