A POST request is used to send data to a server. In Postman, we can use POST requests to test APIs that create new records, such as students, users, products, or courses.
A POST request is an HTTP request used to send data to a server.
For example, when registering a new student, the mobile application can send student information to the server using POST.
POST /students
Postman allows us to create and test POST requests easily.
The basic process is:
Open Postman and create a new HTTP request.
You will see the HTTP method dropdown, URL field, and Send button.
These controls are used to create and send the POST request.
Click the HTTP method dropdown and select POST.
POST
POST tells the server that the client is sending data.
Enter the URL of the API that will receive the data.
Example:
http://localhost/api/students.php
This endpoint will process the student data sent by the POST request.
POST requests commonly send information inside the request body.
For example, a student registration request may contain:
{
"name": "Rahul",
"course": "ADCA",
"mobile": "9876543210"
}
After selecting POST, click the Body tab in Postman.
The Body section provides different ways to send data to the server.
For REST APIs, JSON is commonly used for structured application data.
In the Body section, select raw.
The raw option allows us to enter the request data directly.
After selecting raw, Postman provides a text editor for the request body.
When sending JSON data, select JSON from the format dropdown.
Postman can then send the data as JSON.
{
"name": "Amit",
"course": "Web Development"
}
Enter the data that you want to send to the API.
{
"name": "Priya",
"course": "ADCA",
"mobile": "9876543210"
}
This information will be sent to the server when you click Send.
JSON data is made up of keys and values.
{
"name": "Priya"
}
Here name is the key and Priya is its value.
When sending JSON data, the request should indicate that the body contains JSON.
The header is:
Content-Type: application/json
Postman can add this header automatically when JSON is selected.
After entering the JSON data, click the Send button.
Postman sends the request body to the API server.
POST
↓
API Endpoint
↓
Request Body
↓
Server
The server receives the POST request and reads the request body.
A PHP API can decode the JSON data and use it in the application.
POST Request
↓
PHP API
↓
Read JSON
↓
Validate Data
↓
Save Data
A PHP REST API can use the POST data to insert a new record into MySQL.
For example:
POST JSON
↓
PHP API
↓
MySQL INSERT
↓
New Student Record
Suppose we want to add a new student.
{
"name": "Rahul Kumar",
"course": "ADCA",
"mobile": "9876543210",
"fee": 5000
}
The API can receive this information and create a new student record.
After successfully creating a record, the API can return a JSON response.
{
"status": true,
"message": "Student added successfully"
}
The response tells the client that the operation was successful.
When a POST request successfully creates a new resource, an API can use:
201 Created
This status indicates that a new resource was created successfully.
The API should validate incoming data before saving it.
For example, the API can check whether the student name and mobile number were provided.
{
"status": false,
"message": "Name is required"
}
The API may reject the request when the JSON format is invalid.
Incorrect JSON:
{
"name": "Rahul"
"course": "ADCA"
}
A comma is required between the properties.
The correct JSON should contain commas between multiple properties.
{
"name": "Rahul",
"course": "ADCA"
}
Always check the JSON format before sending the request.
If required data is missing, the API should not insert an incomplete record.
For example:
{
"course": "ADCA"
}
If the name is required, the API should return a validation error.
React Native applications use POST requests when they need to send data to a backend API.
For example:
React Native App
↓
POST Request
↓
PHP REST API
↓
Validate Data
↓
MySQL Database
↓
JSON Response
↓
React Native App
Postman can be used to test the API before connecting it to the mobile app.
If the POST request does not work, check the following:
1. Open Postman
2. Create a request
3. Select POST
4. Enter API URL
5. Open Body
6. Select raw
7. Select JSON
8. Enter JSON data
9. Click Send
10. Check the response
Method:
POST
URL:
http://localhost/api/students.php
Body:
{
"name": "Amit Kumar",
"course": "ADCA",
"mobile": "9876543210"
}
Click Send to submit the student data.
After successfully adding the student, the API might return:
{
"status": true,
"message": "Student added successfully",
"student_id": 15
}
The mobile application can use this response to update its interface.
A POST request is used to send data to a server. In Postman, we can select POST, enter the API URL, add JSON data in the Body section, and click Send.
The server can validate the data, save it to a database, and return a JSON response.
POST
↓
JSON Request Body
↓
PHP REST API
↓
Validation
↓
MySQL
↓
JSON Response
Question: Which HTTP method is commonly used to send data to a server and create a new resource?