What should I return from PUT request?
Repeatedly calling a PUT request always returns the same result (idempotent). The proper status code is returned when creating and updating a resource (eg, 201 or 200 / 204 ). After updating a resource with a PUT request, a GET request for that resource should return the correct data.
What is a good practice that should be followed for a REST API?
REST API Must Accept and Respond with JSON It is a common practice that APIs should accept JSON requests as the payload and also send responses back. JSON is a open and standardized format for data transfer. It is derived from JavaScript in a way to encode and decode JSON via the Fetch API or another HTTP client.
Which status code should a REST API get method return on success?
2xx: Success -Indicates that the client’s request was accepted successfully. 3xx: Redirection – Indicates that the client must take some additional action in order to complete their request. 4xx: Client Error – This category of error status codes points the finger at clients.
What put method returns?
HTTP status code 201 Created for a successful PUT of a new resource, with the most specific URI for the new resource returned in the Location header field and any other relevant URIs and metadata of the resource echoed in the response body. (RFC 2616 Section 10.2. 2)
How are fields specified in the REST API?
Specifies the element of the resource that should be returned from the query. The fields that are available depend upon the method and resource that is the object of the query, and whether the query keyword asks for all fields ( _all_) or the default fields ( _default_ ).
How are resource identifiers used in a REST API?
REST APIs use Uniform Resource Identifiers (URIs) to address resources. REST API designers should create URIs that convey a REST API’s resource model to its potential client developers. When resources are named well, an API is intuitive and easy to use.
When to explicitly specify fields in an API?
Explicitly specify a fields list only if it differs from the default fields list. Specify a fields list that should be excluded (or included) from (to) the default fields set if the desired fields set differs from the default. I want to build a clear and useful API for my customers.
What should I expect from a RESTful API?
The first thing to consider, since you are building a RESTful API, is to return an appropriate response code. And the more appropriate response code to communicate that the request went through normally, but the requested resource is not available at the moment is the venerable 404.