How to return generated ID in RESTful POST?

Viewed 12798

Let's say we have a service to add a new hotel:

> POST /hotel
> <hotel>
>   <a>aaa</a>
>   <b>aaa</b>
>   <c>aaa.......this is 300K</c>
> </hotel>

And then we have a get:

> GET /hotel

< HTTP/1.1 200 OK
< <hotel>
<   <a>aaa</a>
<   <b>aaa</b>
>   <c>aaa.......this is 300K</c>
< </hotel>

Question is what do we return for the initial POST creation? We would like to return the ID (generated on the server) for a "reference" to the new resource but we don't want to return all the hotel data as in our case one of the data fields is a flat file of ~300K.

So should you just return:

< HTTP/1.1 200 OK
< <hotel>
<   <id>123</id>
< </hotel>

Or should you return the full object:

< HTTP/1.1 200 OK
< <hotel>
<   <id>123</id>
<   <a>aaa</a>
<   <b>aaa</b>
>   <c>aaa.......this is 300K</c>
< </hotel>

??

I'm interested in the restful best practice.

Note: this related post talks more about what to return but less about how to return it.

3 Answers
Related