Lesson 33 of 158 – First Postman Request
33%

First Postman Request

Now that Postman is installed, it is time to create our first API request. In this lesson, we will learn how to select an HTTP method, enter an API URL, send the request, and understand the response.

This is an important step because the same API request that we test in Postman can later be called from our React Native application.

Note: Postman sends the HTTP request directly to the API server. It does not need a React Native application to test the backend.

1. What is an API Request?

An API request is a message sent by a client to a server asking it to perform an operation or return information.


Client
   ↓
API Request
   ↓
Server
   ↓
API Response

Postman acts as the client when we test an API.

2. Postman as an API Client

Postman can behave like a client application and send HTTP requests to a REST API.


Postman
   ↓
HTTP Request
   ↓
REST API
   ↓
HTTP Response

This allows us to test the backend independently.

3. Create a New Request

Open Postman and create a new HTTP request.

A request normally contains:

  • HTTP method
  • Request URL
  • Headers
  • Query parameters
  • Request body when required

For our first request, we will keep the request simple.

4. Select the HTTP Method

The first step is to select the HTTP method.

For our first request, select:


GET

GET is commonly used to retrieve information from a server.

5. Enter the API URL

After selecting GET, enter the URL of the API endpoint.

For example:


https://example.com/api/students

The URL must point to an actual API endpoint for the request to return the expected API response.

6. Local API URL

When developing a PHP REST API locally, the URL may look like:


http://localhost/rest_api/api/students.php

The exact URL depends on your local PHP project folder and API file.

7. Click Send

After selecting GET and entering the URL, click the Send button.


GET
   +
API URL
   ↓
Send
   ↓
Server
   ↓
Response

Postman sends the HTTP request to the specified server.

8. What Happens After Send?

When you click Send, Postman sends the request to the server. The server processes the request and returns a response.


Postman
   ↓
GET Request
   ↓
Server
   ↓
Process Request
   ↓
Response
   ↓
Postman

9. Understanding the Response

Postman displays the response returned by the server.

Important response information includes:

  • Status code
  • Response time
  • Response headers
  • Response body

10. Example 200 OK Response

If the API request is successful, the server may return:


200 OK

For example, the response body could be:


{
    "success": true,
    "message": "API is working"
}

11. Reading JSON Response

If the REST API returns JSON, Postman displays the JSON response in the response body.


{
    "success": true,
    "message": "Students found",
    "data": []
}

JSON is commonly used for communication between REST APIs and mobile applications.

12. Checking the Status Code

Always check the HTTP status code after sending an API request.

Status Meaning
200 Request succeeded
201 Resource created
400 Bad request
401 Unauthorized
404 Resource not found
500 Server error

13. Checking Response Time

Postman also displays the time taken by the server to return the response.

Response time can be useful when investigating API performance.


Request
   ↓
Server Processing
   ↓
Response
   ↓
Response Time

14. Checking Response Headers

The response headers contain additional information about the response.

For example:


Content-Type: application/json

This tells the client that the response body contains JSON.

15. First Request Without a Body

A simple GET request usually does not require a request body.


GET /api/students

The API URL itself identifies the resource that we want to retrieve.

16. Adding Accept Header

We can add an Accept header to indicate that we expect JSON.


Accept: application/json

In Postman, this can be added from the Headers section.

17. Request Headers Section

The Headers section allows you to add information to the request.

Header Example Value
Accept application/json
Content-Type application/json
Authorization Bearer TOKEN

18. GET Request with Header

Our first request can now look like:


GET /api/students

Accept: application/json

The server can return JSON data if the endpoint supports it.

19. Testing a PHP API

Suppose our PHP API is located at:


http://localhost/rest_api/api/students.php

In Postman:

  1. Select GET.
  2. Enter the URL.
  3. Add Accept: application/json if required.
  4. Click Send.
  5. Check the response.

20. Testing a Simple API Response

Suppose the PHP API contains:


header(
    "Content-Type: application/json"
);

echo json_encode([
    "success" => true,
    "message" => "API is working"
]);

Postman should receive a JSON response similar to:


{
    "success": true,
    "message": "API is working"
}

21. API URL Error

If the URL is incorrect, the server may return a 404 response.


404 Not Found

Check:

  • Domain name
  • Folder name
  • API file name
  • Endpoint path
  • Port number if applicable

22. Server Not Running

If your local PHP server is not running, Postman will not be able to communicate with the local API.


Postman
   ↓
localhost
   X
PHP Server Not Running

Start your local web server before testing a local PHP API.

23. Invalid API Response

If the API returns invalid JSON, Postman can help you identify that the response is not structured as expected.

A valid JSON response can look like:


{
    "success": true,
    "message": "Success"
}

Make sure JSON syntax is correct in your PHP API.

24. Postman Request and React Native

The request tested in Postman can later be implemented in React Native.


Postman:

GET
/api/students
Accept: application/json

↓

React Native:

fetch(
    "https://example.com/api/students",
    {
        headers: {
            "Accept":
                "application/json"
        }
    }
);

25. Common First Request Mistakes

  • Selecting the wrong HTTP method.
  • Entering the wrong URL.
  • Forgetting to start the local server.
  • Using the wrong port.
  • Testing an endpoint that does not exist.
  • Using incorrect headers.
  • Ignoring the response status code.
  • Not checking the response body.

26. Debugging the First Request

If your first request does not work, check the following sequence:


1. Is the server running?
2. Is the URL correct?
3. Is the HTTP method correct?
4. Does the endpoint exist?
5. Are the headers correct?
6. What status code was returned?
7. What does the response body say?

27. First Request Checklist

  • Postman is installed.
  • Postman is open.
  • A new request is created.
  • GET is selected.
  • The API URL is entered.
  • The server is running.
  • The Send button is clicked.
  • The response is inspected.

28. Complete First Request Flow


Open Postman
      ↓
Create Request
      ↓
Select GET
      ↓
Enter API URL
      ↓
Add Headers if Required
      ↓
Click Send
      ↓
Server Processes Request
      ↓
Receive Response
      ↓
Check Status Code
      ↓
Check JSON Body

29. Complete First Student Request

Let's imagine that our student API is available at:


http://localhost/rest_api/api/students.php

Configure Postman like this:


Method:
GET

URL:
http://localhost/rest_api/api/students.php

Header:
Accept: application/json

Click Send. If the API is working, Postman will display the response from the PHP server.

30. Complete First Postman Request

Creating the first Postman request is simple: select the HTTP method, enter the API URL, configure headers if required, send the request, and inspect the response.


POSTMAN
   ↓
GET
   ↓
API URL
   ↓
SEND
   ↓
PHP REST API
   ↓
JSON RESPONSE
   ↓
POSTMAN

Once you understand this basic process, you can use Postman to test POST, PUT, PATCH and DELETE requests as well as authentication, parameters and JSON request bodies.

📌 Key Points

  • Postman can act as an API client.
  • An API request contains a method and URL, and may contain headers, parameters and a body.
  • GET is commonly used to retrieve data.
  • The API URL identifies the endpoint.
  • The Send button sends the request to the server.
  • Postman displays the API response.
  • Always check the HTTP status code.
  • Check the response headers and response body.
  • JSON is commonly used in REST API responses.
  • Accept: application/json can indicate that JSON is expected.
  • Local PHP APIs can be tested using localhost URLs.
  • The local PHP server must be running for a local API to respond.
  • Incorrect URLs can result in 404 errors.
  • Postman can help debug API problems.
  • The same API tested in Postman can later be connected to React Native.

🧠 Quick Quiz

Question: Which HTTP method should you commonly select in Postman when you want to retrieve data from an API?