Appropriate response for registering a customer via REST API

160 views
Skip to first unread message

Vivek Gounder

unread,
Jul 17, 2014, 8:38:51 AM7/17/14
to resting-wi...@googlegroups.com
Hello all,

I was wondering whats the ideal response body a client should get back after registering a customer in your system?

Miguel Ángel Sánchez Chordi

unread,
Jul 18, 2014, 4:01:08 AM7/18/14
to resting-wi...@googlegroups.com
Well, I think this is up to you, there's no exist a standard response.

For example:
  • Response with a 201 code and return the ID of the new resource.
  • Response with a 201 code and return the whole resource (just for the client verify everything is OK)
  • Response with a 202 code if you need to manually validate something (by a phone call for instance) and a URL to check the status of the process.
  • Response with a 204 and an empty body (I don't recommend this option, client needs to now almost his new ID)
  • Response with a 200 and a confirmation message
I think I always use the first option, because I think my client needs to know what is his identifier.

Larry Garfield

unread,
Sep 6, 2014, 3:22:24 PM9/6/14
to resting-wi...@googlegroups.com
The internal ID of the object is irrelevant from a REST POV.  What you should send back is a 201 with a Location header of where the just-created resource can be found, eg, Location: /customer/12345.  That "12345" is an ID in your SQL table is irrelevant.

Sending back the full object with it as well is a nice convenience, but optional.  I usually do so myself.

--Larry Garfield
Reply all
Reply to author
Forward
0 new messages