1

There was a debate with one of the platform engineers (as a mobile dev), about the codes being returned.

The scenario is: when trying to create a resource the server is returning a 201 with the resource_id in the header. I would have expected a 201 response with a JSON body with the resource_id. In my opinion, this would be easier for the mobile clients to parse.

Am I wrong in thinking this way? Should I be really parsing headers?

asked Jan 27, 2015 at 22:50

2 Answers 2

3

Looking at RFC2616, in the section about the 201 Created response code, we find:

The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field.

So, putting that resource identifier in a Location header field is perfectly legitimate. But, reading further, we find:

The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field.

In other words, the server should provide the new resource location as part of the body of the response, formatted according to the requested content type.

answered Jan 28, 2015 at 0:42
1

For update, you shouldn't need to parse anything other than the Status Code. The updated content comes from the client so only the server needs to do the updating which after it finished it should just return 204 (No Content).

answered Jan 28, 2015 at 1:45
1
  • 1
    Agreed. I meant create and not update. Got confused. Sorry. Commented Jan 28, 2015 at 1:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.