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/]

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
ccoveille profile image
Christophe Colombier โ€ข

HTTP can be fun also

dev.to/ccoveille/comment/2ek7e

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

๐Ÿ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay