Lesson 35 of 158 – Postman POST Request
35%

Postman POST Request

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.

Note: POST requests are commonly used when a mobile application needs to send new information to the server.

1. What is a POST Request?

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

2. POST Request in Postman

Postman allows us to create and test POST requests easily.

The basic process is:

  1. Select POST
  2. Enter the API URL
  3. Open the Body section
  4. Enter the data
  5. Click Send
  6. Read the response

3. Create a New POST Request

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.

4. Select POST Method

Click the HTTP method dropdown and select POST.

POST

POST tells the server that the client is sending data.

5. Enter the API URL

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.

6. Why Does POST Need a Body?

POST requests commonly send information inside the request body.

For example, a student registration request may contain:

{
    "name": "Rahul",
    "course": "ADCA",
    "mobile": "9876543210"
}

7. Open the Body Section

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.

8. Select raw Body

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.

9. Select JSON Format

When sending JSON data, select JSON from the format dropdown.

Postman can then send the data as JSON.

{
    "name": "Amit",
    "course": "Web Development"
}

10. Enter JSON Data

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.

11. JSON Keys and Values

JSON data is made up of keys and values.

{
    "name": "Priya"
}

Here name is the key and Priya is its value.

12. Content-Type Header

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.

13. Send the POST Request

After entering the JSON data, click the Send button.

Postman sends the request body to the API server.

POST
    ↓
API Endpoint
    ↓
Request Body
    ↓
Server

14. Server Receives POST Data

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

15. POST Data and MySQL

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

16. Example Student POST Data

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.

17. Successful POST Response

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.

18. Status Code 201 Created

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.

19. Validation Error

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"
}

20. Invalid JSON

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.

21. Correct JSON

The correct JSON should contain commas between multiple properties.

{
    "name": "Rahul",
    "course": "ADCA"
}

Always check the JSON format before sending the request.

22. POST Request Without Required Data

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.

23. POST Request and React Native

React Native applications use POST requests when they need to send data to a backend API.

For example:

  • User registration
  • Login requests
  • Adding students
  • Submitting forms
  • Creating products

24. Postman POST and Mobile App Flow

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.

25. Common POST Request Mistakes

  • Wrong API URL
  • Wrong HTTP method
  • Invalid JSON
  • Missing required fields
  • Incorrect Content-Type
  • Server not running
  • Database connection error

26. Debugging a POST Request

If the POST request does not work, check the following:

  1. Check the API URL.
  2. Confirm POST is selected.
  3. Check the Body section.
  4. Check JSON syntax.
  5. Check Content-Type.
  6. Check the server.
  7. Check the PHP API.
  8. Check the database.

27. Complete POST Request Flow

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

28. Complete POST Example

Method:

POST

URL:

http://localhost/api/students.php

Body:

{
    "name": "Amit Kumar",
    "course": "ADCA",
    "mobile": "9876543210"
}

Click Send to submit the student data.

29. Example POST Response

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.

30. Postman POST Request Summary

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

📌 Key Points

  • POST is commonly used to send data to a server.
  • POST requests commonly use a request body.
  • JSON is commonly used for structured API data.
  • Postman can send JSON data using the Body section.
  • The Content-Type header can identify JSON data.
  • The API should validate incoming data.
  • POST can be used to create new records.
  • 201 Created can indicate that a resource was successfully created.
  • PHP APIs can save POST data into MySQL.
  • React Native applications can use POST requests to submit data.

🧠 Quick Quiz

Question: Which HTTP method is commonly used to send data to a server and create a new resource?