Returns a subset of the view in a POST REST violation?

If I upload a new resource with 100 fields, and the server adds 3 own fields, such as date, status, etc., then RESTful returns only a mini-representation of the resource, which includes only 3 new fields in the response body of CREATED 201?

Then the client can simply add these 3 new fields to the local view. I have seen calls that you should always send the full view, but it seems that the waste of bandwidth returns all 103.

+4
source share
3 answers

The response object 201 (the body of the response itself) does not have to be or is considered by some http client as the resource you just created.

This is a view that describes the result.

If you want people to access the newly created resource, they can do this by sending a request to the URI in the Location header, which returns from 201.

If you return the body of the object to 201, it is not considered by HTTP as the resource you just created, so you can return whatever you want.

The important thing is the type of media object that you are returning. If this object is known to the client, whether it is a smaller or full version of the object, they will know what to do with it. If you expect the client to β€œknow” that the type of media being returned to 201 is the minimum version, you provide strong interaction with your own protocol, which violates the principles of ReST.

+4
source

There are no rules that state that you need to return a complete answer in a REST or HTTP RFC dissertation. The latter ( RFC 2616, HTTPbis version ) has this to say about the 201 Status Code Created:

If the resource was created on the source server, the response MUST be 201 (created) and contain an object that describes the status of the request and refers to the new resource and the Location header.

Returning the information that has been added is a reasonable and completely RESTful HTTP compatible idea.

+1
source

It completely depends on what you answer, although it may be an idea to provide a link to additional information about the resource. If you want to get really fantasy, you can specify microformat

+1
source

All Articles