Useful HTTP codes

Another important aspect of a good RESTful API is to use HTTP codes in a sensible way. The HTTP specification defines a lot of standard codes. They should cover 99 percent of what a good API needs to communicate to its users. The following list contains the most important codes, the ones every API should use and every developer should know:

Code

Meaning

Usage

2xx - Success

These codes are used when everything goes well.

 

200

Everything is okay.

The request succeeded.

201

A resource has been created.

The successful creation of a resource. The response should include a list of locations associated with the creation.

204

There is no content to return.

The server has successfully handled the request but there is no content to return.

3xx - Redirection

These codes are used when further action is needed on the client to fulfill the request.

 

301

Moved permanently

The resource has a changed URI and its new location is indicated in the Location header.

304

The resource has not been modified.

The resource has not changed since the last time. This response must include the date, ETag, and cache information.

4xx - Client error

The request was not successfully performed because of a mistake made by the client.

 

400

Bad request

The data sent by the client could not be understood.

403

Forbidden

The request was understood but not allowed. This can be enriched with information describing the error.

404

Not found

Nothing matches this URI. This can be used instead of 403 if information about security shouldn't be disclosed.

409

Conflict

The request conflicts with another modification. The response should include information on how to resolve the conflict.

5xx - Server error

An error occurred on the server side.

 

500

An internal server error

The server unexpectedly failed to process the request.

Note

For a more detailed list, see http://www.restapitutorial.com/httpstatuscodes.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.171.153