API Status codes and some categories

WHAT ARE STATUS CODES?

If a valid request comes in for data, you return the data. If creating an object on the API with valid data, you return the created object.

A server responds to a request from a client by returning a status code. They are used in all responses and have a number from 200 to 507 - with a lot of gaps in between - and each one of the codes has a message and a definition.

They are grouped into different categories:

  • 2xx is all about success:

These status codes signify that the request has been successfully received, accepted, and resolved. Everything the client attempted to perform was successful up until the response was sent. However, a status code like "202 Accepted" just signifies that the request was accepted and is being processed asynchronously and says nothing about the actual outcome.

  • 3xx is all about redirection:

When the client needs to take further action to complete the request, the server often returns a 3xx redirection status code. It is all about sending the calling application somewhere else for the actual resource. The most popular ones on the web to direct a browser to another URL are "303 See Other" and "301 Moved Permanently."

  • 4xx is all about client errors:

If a client request results in an issue, the server often returns a status code of 4xx. With these status codes, it is possible to indicate that the client has send an invalid request and needs to fix it before getting a response.

  • 5xx is all about service errors:

The 5xx status codes denote a request that was successful but had a server-side issue. These codes might be used to indicate that there was a problem with the server service. For instance, connection issues prevented communication from reaching the database. Most of the time, the client has the option to retry the request.

SOME STATUS CODES

You can find a comprehensive list of status codes online. These status codes, though, are those that are frequently used.

200 - Generic everything is OK

201 - Created something OK

202 - Accepted but is being processed async (for an image means it is being resized)

400 - Bad Request (mostly for invalid syntax, but some use for validation

401 - Unauthorized

403 - That current user is forbidden from accessing this data

404 - That URL is not a valid route, or the item resource does not exist

405 - Method Not Allowed

410 - Data has been deleted, deactivated or suspended

500 - Something unexpected happened, and it is the APIs fault

503 - API is not here right now, please try again later