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

Sospeter Mong'are - May 9 - - Dev Community

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .