HTTP status codes are numbers returned by a web server to describe the result of an HTTP request.
When a React Native application communicates with a REST API, the server sends a status code along with the response. The mobile application can use this code to understand whether the request was successful or whether an error occurred.
An HTTP status code is a three-digit number returned by a server after processing an HTTP request.
Example:
HTTP/1.1 200 OK
Here, 200 is the status code and OK describes the result.
Status codes allow the client to understand what happened after sending a request.
For example:
HTTP status codes are divided into five main categories.
| Range | Category |
|---|---|
| 100–199 | Informational responses |
| 200–299 | Successful responses |
| 300–399 | Redirection responses |
| 400–499 | Client error responses |
| 500–599 | Server error responses |
Status codes from 100 to 199 are informational responses. They indicate that the request has been received or that the communication is continuing.
These responses are less commonly handled directly in basic React Native REST API applications.
1xx
↓
Informational
Status codes from 200 to 299 indicate successful processing of a request.
Common examples include:
Status codes from 300 to 399 are related to redirection.
They can indicate that the requested resource or response requires another step or location.
3xx
↓
Redirection
Basic REST API development usually focuses more heavily on 2xx, 4xx, and 5xx responses.
Status codes from 400 to 499 generally indicate that there is a problem with the request from the client side.
Common examples include:
Status codes from 500 to 599 generally indicate that the server encountered an error while processing the request.
Common examples include:
200 OK indicates that the request was successfully processed.
For example, a GET request that successfully retrieves students can return:
HTTP/1.1 200 OK
{
"success": true,
"data": [
{
"id": 1,
"name": "Rahul"
}
]
}
201 Created indicates that a new resource was successfully created.
It is commonly used after a successful POST request.
POST /api/students
HTTP/1.1 201 Created
The response can contain information about the newly created resource.
202 Accepted indicates that the request has been accepted for processing, but processing may not have completed yet.
HTTP/1.1 202 Accepted
This can be useful when an operation is handled asynchronously.
204 No Content indicates that the request was successfully processed but there is no response body to return.
It can be used for operations such as successful updates or deletions.
HTTP/1.1 204 No Content
400 Bad Request indicates that the server cannot properly process the request because the request is invalid.
For example:
HTTP/1.1 400 Bad Request
401 Unauthorized indicates that the request requires valid authentication credentials.
For example, a protected API may require an access token.
HTTP/1.1 401 Unauthorized
The React Native application can respond by asking the user to log in or refresh authentication.
403 Forbidden indicates that the server understood the request but refuses to authorize it.
For example, a normal user may not have permission to delete a student record.
HTTP/1.1 403 Forbidden
This is commonly related to authorization or permissions.
404 Not Found indicates that the requested resource could not be found.
Example:
GET /api/students/9999
If student 9999 does not exist, the API may return:
HTTP/1.1 404 Not Found
405 Method Not Allowed indicates that the HTTP method used is not supported for the requested resource.
For example, an endpoint may support GET but not DELETE.
HTTP/1.1 405 Method Not Allowed
409 Conflict indicates that the request conflicts with the current state of the resource.
For example, an API might return 409 when a registration attempts to create a record that conflicts with an existing unique value.
HTTP/1.1 409 Conflict
422 Unprocessable Content can be used when the server understands the request but cannot process the submitted data because it does not satisfy the required validation rules.
For example:
HTTP/1.1 422 Unprocessable Content
500 Internal Server Error indicates that the server encountered an unexpected condition while processing the request.
For a PHP REST API, this may be caused by an unexpected application error, database problem, or server configuration issue.
HTTP/1.1 500 Internal Server Error
503 Service Unavailable indicates that the server is currently unable to handle the request.
This can happen when a service is temporarily unavailable or overloaded.
HTTP/1.1 503 Service Unavailable
React Native can check the HTTP response using the Fetch API.
const response = await fetch(
"https://example.com/api/students"
);
console.log(response.status);
if (response.ok) {
console.log("Request successful");
}
The status property contains the numeric HTTP status code.
The mobile application can handle different status codes separately.
if (response.status === 200) {
console.log("Success");
} else if (response.status === 401) {
console.log("Please login");
} else if (response.status === 404) {
console.log("Resource not found");
} else if (response.status >= 500) {
console.log("Server error");
}
| Operation | Common Success Code |
|---|---|
| GET | 200 OK |
| POST | 201 Created |
| PUT | 200 OK or 204 No Content |
| PATCH | 200 OK or 204 No Content |
| DELETE | 200 OK or 204 No Content |
The exact status code depends on the API's design and response requirements.
PHP can send an HTTP status code using http_response_code().
http_response_code(201);
header("Content-Type: application/json");
echo json_encode([
"success" => true,
"message" => "Student created"
]);
This allows the REST API to communicate the result clearly to the client.
An API can send both an HTTP status code and a JSON error message.
http_response_code(404);
echo json_encode([
"success" => false,
"message" => "Student not found"
]);
React Native can check the status code and then read the JSON message.
Postman displays the HTTP status code after an API request is sent.
For example, after sending a request, Postman may show:
200 OK
or:
404 Not Found
This makes Postman useful for testing REST APIs before connecting them to React Native.
React Native
↓
Send API Request
↓
PHP REST API
↓
Process Request
↓
HTTP Status Code
+
JSON Response
↓
React Native
↓
Show Success or Error
Status codes help the mobile application decide how to respond to the server's result.
HTTP status codes provide a standard way for a REST API to communicate the result of an HTTP request.
2xx → Success
3xx → Redirection
4xx → Client Error
5xx → Server Error
A React Native application can use these status codes together with JSON responses to decide whether to display data, show validation messages, request authentication, or report a server problem.
Question: Which HTTP status code commonly indicates that a request was successful?