Proper response for a REST insert - full new record, or just the record id value?

Posted by Keith Palmer on Programmers See other posts from Programmers or by Keith Palmer
Published on 2012-10-24T03:48:48Z Indexed on 2012/10/24 5:25 UTC
Read the original article Hit count: 273

Filed under:

I'm building a REST API which allows inserts (POST, not idempotent) and updates (PUT, idempotent) requests to add/update database to our application.

I'm wondering if there are any standards or best practices regarding what data we send back to the client in the response for a POST (insert) operation. We need to send back at least a record ID value (e.g. your new record is record #1234).

Should we respond with the full object? (e.g. essentially the same response they'd get back from a "GET /object_type/1234" request)

Should we respond with only the new ID value? (e.g. "{ id: 1234 }", which means that if they want to fetch the whole record they need to do an additional HTTP GET request to grab the full record)

A redirect header pointing them to the URL for the full object?

Something else entirely?

© Programmers or respective owner

Related posts about rest