Q:

Should a REST server send whole object or just id on POST?

Given a RESTful server backend that uses JSON encoding for objects. The GET request return the object like { id: 42, name: 'Peter', age: 28 }. Now I wonder whether the POST request, which inserts a new object, should return the whole object in the same form, or just return the created id.
For example the client sends this request to create a new entry in database.
method:  POST
url:     http://example.com/persons
type:    application/json
content: { name: 'Max', age: 35 }

Should the server respond with { id: 43, name: 'Max', age: 35 } or just with the created id like 43 or { id: 43 }?
In this minimal example, I guess bandwidth wouldn't really matter, but actually, there are longer properties encoding geographical areas involved.

A:

I am not aware of any guidelines. Personally, I think it may be useful to return the data the client cannot know – primarily the new ID, of course, but the server may have canonicalized or otherwise changed other data as well.
But in the end, it just depends on what the client wants to do with the data. If returning anything at all, I'd use a format that is open for further extension, not just a numerical ID or anything like that.

