REST API Status Codes

REST API Durum Kodları


REST API Status Codes

 Hello everyone, these days I have to use REST API for user operations etc. in one of my projects and while developing an application on the backend using a REST API, there are some rules that we must follow. 

It is especially important to follow these rules to inform the client about events on the server side. Especially if you want your code to be understood by everyone, I can say that complying with internationally established standards is inevitable. Come on, let's take a look at which values the values ("status") returned on the server side mean when developing an application with REST API.

Methods and the Status Codes They Receive

ActionStatus Code
GET200, 401, 403, 404
POST200, 201, 401, 403, 404 , 422
PUT200, 401, 403, 404 , 422
PATCH200, 401, 403, 404 , 422
DELETE200, 401, 403, 404 , 422

Status Codes and Their Meanings

Let's take a general look at the status codes.
  • 1xx - Informational Request.
  • 2xx - Request successful.
  • 3xx - Request redirected. Rarely used.
  • 4xx - Client Errors (usually codes like 401, 404).
  • 5xx - Server error (usually 500).
Now that we've taken a general look at which codes that start with which digits represent, let's examine it a little more code-based.

CodeCode Description
200OK!, Everything went smoothly.
201Generally used in cases where data is added to the database via post, and it indicates that the data has been added successfully.
The added data is returned in the "body" of the response.
202Indicates that the client's request has been accepted. (Not used often.)
203Used for cached values.
400Indicates a bad request.
401Indicates that an invalid API key was provided.
402Indicates that payment is required, i.e., it is a paid service.
403Indicates that there is no access permission.
404Returned when a resource cannot be found, indicates that the searched object is not found on the server.
405Indicates there are disallowed conditions.
422Unprocessable entity. Indicates missing fields or invalid XML or JSON.
429Indicates that too many requests have been made, i.e., too many attempts.
500Indicates a server-side error.