DEV Community

Sospeter Mong'are
Sospeter Mong'are

Posted on

๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—›๐—ง๐—ง๐—ฃ ๐—ฆ๐˜๐—ฎ๐˜๐˜‚๐˜€ ๐—–๐—ผ๐—ฑ๐—ฒ ๐—ถ๐˜€ ๐˜๐—ต๐—ฒ ๐—ฐ๐—ผ๐—ฟ๐—ฟ๐—ฒ๐—ฐ๐˜ ๐—ผ๐—ป๐—ฒ?

HTTP Status Codes indicate the result of an API request.

They're represented as three-digit codes.

There are different types of HTTP status codes:

  • 1xx informational responses
  • 2xx success responses
  • 3xx redirection responses
  • 4xx client error responses
  • 5xx server error responses

Which HTTP status code you should use depends on what you want to communicate to your API clients. They're used to communicate if the request was successful or not. HTTP status codes also carry semantic information.

Some of the most popular HTTP Status Codes are:

  • 200 OK
  • 400 Bad Request
  • 404 Not Found
  • 500 Internal Server Error

But just returning random status codes won't help.

So here are 5 best practices I use for HTTP status codes:

  • 201 when creating a new resource
  • 400 when there is a validation error
  • 404 when a resource is not found
  • 409 when a resource already exists
  • Include a Problem Details response for errors

Learn more about HTTP Status Codes here: [https://blog.postman.com/what-are-http-status-codes/]

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (1)

Collapse
 
ccoveille profile image
Christophe Colombier โ€ข

HTTP can be fun also

dev.to/ccoveille/comment/2ek7e

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay