Using the correct HTTP methods and status codes in your RESTful API

Doing something with your resources: use HTTP methods

  • POST: creates a new resource
  • GET: reads one or more resources
  • PUT / PATCH: updates a resource
  • DELETE: deletes a resources

PUT vs PATCH

PUT /user/123{
id: "123",
email: "guillaume@gvj-web.com",
first_name: "Guillaume",
last_name: "Viguier"
}
PATCH /user/123{
email: "guillaume@gvj-web.com"
}

Handling responses: use proper HTTP status codes

  • 200 OK: the request succeeded, and data is being returned.
  • 201 Created: A new resource has been created, as a result of a call to this request. The Location header points to the URI of the new resource
  • 204 No Content: the request was successful, but no data is being returned (used for example after a DELETE request)
  • 400 Bad Request: the request could not be understood by the server due to wrong syntax (for example and attribute was in the wrong format)
  • 401 Unauthorized: the request requires authentication. The request COULD eventually be fulfilled with proper user authentication.
  • 403 Forbidden: the user is authenticated, but does not have permission to fulfill this request
  • 404 Not Found: the resource could not be found
  • 429 Too Many Requests: returned when a rate limit has been reached
  • 500 Internal server error: something is wrong with the server or the implementation

--

--

--

Développeur web et passionné de finances personnelles

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating a Prefab for my Triple Shot Powerup

Everything you wanted to know about media metadata, but were afraid to ask

The resilience of systems: definitions and components.

PlayerOne second beta testing

Leverage your productivity while on Windows

Learn Python From Scratch As a Frontend Developer

Understanding resource limits in Kubernetes

How to convert bootstrap mobile navbar to a sidebar

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Guillaume Viguier-Just

Guillaume Viguier-Just

Développeur web et passionné de finances personnelles

More from Medium

GraphQL Explained In Under 7 Minutes

Locking solution for Axios requests

Adventures in Streaming to Http Requests in NodeJS

Making Simple Object Schema Validation even Simpler with React Custom Hooks and YUP!