Skip to content

Instantly share code, notes, and snippets.

@pfigue
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save pfigue/c1a3a6a91aec89c04679 to your computer and use it in GitHub Desktop.

Select an option

Save pfigue/c1a3a6a91aec89c04679 to your computer and use it in GitHub Desktop.
REST Notes and Answers: Status code semantics

REST API Answer Status Codes

Why?

I am designing an API, which status code should each method return back to the client?

What?

HTTP Response Status Example Use Case(s)
200 OK
201 Created Answer to a successful POST /resource/
202 Accepted Answer to a successful POST /resource/
410 Gone A resource accepted for creation was finally not created
404 Not Found A resource doesn't exist

Describing REST APIs CRUD

Elements

In REST there are Resources and Collections of resources.

Resource Creation

This is requested through an POST /resource/ method.

Upon creation of a resource, an API can return 201 Created and then an URI to the newly created resource in the response body. A copy of the new resource in the answer is not needed. Not always the request for the creation of a resource results in the creation of the resource, but just in accepting (202 Accepted) the request. Later, the resource may be created (or not).

More

Links:


Created with http://www.tablesgenerator.com/markdown_tables

Preview with http://dillinger.io/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment