Handling API Pagination
Many APIs return large datasets in multiple pages instead of sending all records in a single response. This technique is known as pagination.
In Postman, handling pagination involves making repeated API requests until all pages have been retrieved.
A typical paginated request looks like:
GET https://api.example.com/users?page=1&size=10
Here:
pagespecifies which page to retrieve.sizespecifies the number of records returned per page.
Most APIs return a limited number of records (such as 10, 50, or 100) in each request.
How Pagination is Handled
Typically, a pre-request script or test script:
- Checks whether a
nextPagevalue exists. - Automatically sends another request for the next page.
- Continues until no additional pages remain.
Interview Tip:
"We used Postman scripts to automatically detect thenextPageparameter and continue sending requests until every page was retrieved, allowing us to validate the complete dataset instead of just the first page."
Using Postman with GraphQL APIs
GraphQL is a query language for APIs that allows clients to request only the data they actually need.
Unlike REST APIs, GraphQL avoids over-fetching by returning only the requested fields.
Postman provides built-in support for testing GraphQL APIs.
Steps to Use GraphQL in Postman
- Select the POST request method.
- Enter the GraphQL endpoint.
https://example.com/graphql
- Open the Body tab.
- Select GraphQL.
- Write the GraphQL query.
- Add variables if required.
- Send the request.
Validating and Debugging
You can:
- Validate responses using Postman Test Scripts.
- Debug requests using the Postman Console (
Ctrl + Alt + C).
Interview Tip:
"GraphQL lets clients request only the required fields in a single API call, reducing unnecessary data transfer and improving performance."
Working with SOAP APIs
SOAP (Simple Object Access Protocol) is a protocol for exchanging structured information using XML-based messages.
Unlike REST APIs, which typically use JSON, SOAP uses XML for both requests and responses.
Key Features of SOAP
- Uses XML for requests and responses.
- Follows strict standards.
- Uses a WSDL (Web Services Description Language).
- Structures messages using SOAP Envelopes.
Steps to Test SOAP APIs in Postman
- Select the POST method.
- Enter the SOAP endpoint.
https://www.example.com/soap-service
- Set the request body format to XML (text/xml).
- Add the SOAP request wrapped inside a SOAP Envelope.
- Include the required request headers.
- Add the SOAPAction header to specify the operation.
- Send the request.
A successful request returns an XML response that can be validated using Postman Test Scripts.
Interview Tip:
"When testing SOAP services, I send XML requests wrapped in SOAP Envelopes, include the SOAPAction header, and validate the XML response using Postman test scripts."
REST vs GraphQL
| Aspect | REST | GraphQL |
|---|---|---|
| Endpoints | Multiple endpoints | Single endpoint |
| Response | Fixed response structure (may over-fetch data) | Returns only requested fields |
| Performance | May require multiple API calls | Fewer API calls for complex data |
| Real-Time Support | Limited | Supports subscriptions |
| Best Use Case | Simple APIs | Complex and data-heavy applications |
Example
REST
GET /users/1
The API may return more information than required.
GraphQL
A single query requests only the fields needed.
This reduces unnecessary data transfer and improves efficiency.
When to Use Each
- Use REST for simple applications that require straightforward API design.
- Use GraphQL for applications with dynamic, nested, or complex data requirements.
Mock APIs and Mock Servers
A Mock API simulates the behavior of a real API without requiring an actual backend server.
Postman includes a built-in Mock Server feature that returns predefined responses.
Why Use Mock APIs?
- Develop APIs before the backend is available.
- Test frontend applications independently.
- Simulate real API responses.
- Test error handling.
- Simulate slow responses.
- Validate edge cases.
Creating a Mock Server in Postman
Follow these steps:
- Create a new collection.
- Add a request.
- Define the mock response.
- Open Body → Raw → JSON.
- Save the response.
- Click More Actions on the collection.
- Select Mock Collection.
- Choose Create Mock Server.
- Enter a name.
- Optionally save the mock URL as an environment variable.
Postman generates a mock endpoint similar to:
https://mock-server.postman.com/mock/12345/users
You can send requests to this URL exactly like a real API.
Interview Tip:
"We used Postman Mock Servers to allow frontend development to continue even before the backend APIs were implemented."
Generating API Documentation
Postman can automatically generate API documentation directly from a collection.
The generated documentation includes:
- Request methods
- URLs
- Headers
- Request bodies
- Parameters
- Sample responses
- Example requests
This documentation can be shared with team members or published externally.
Since the documentation is generated from the collection itself, it stays synchronized with the latest API requests.
Interview Tip:
"We generated API documentation directly from Postman collections, ensuring our documentation remained consistent with the actual API implementation."
FAQs
How do you handle API pagination in Postman?
Use page and size query parameters and write a Postman script that follows the nextPage value until all pages have been retrieved.
How do you use Postman with GraphQL?
Use the POST method, enter the GraphQL endpoint, select GraphQL in the Body tab, write the query and variables, then validate responses using Postman Test Scripts and debug using the Postman Console.
How do you work with SOAP APIs in Postman?
Use the POST method with an XML request wrapped inside a SOAP Envelope, add the required headers including SOAPAction, and validate the XML response using Postman Test Scripts.
What is the difference between REST and GraphQL?
REST uses multiple endpoints and fixed responses, which can sometimes return unnecessary data.
GraphQL uses a single endpoint and allows clients to request only the fields they need, reducing over-fetching and improving efficiency.
What is a Mock Server in Postman?
A Mock Server is a simulated API that returns predefined responses without requiring a real backend, allowing development and testing to continue independently.
How do you generate API documentation in Postman?
Postman automatically generates documentation from a collection, including request methods, URLs, headers, request bodies, parameters, and example responses, making it easy to share and maintain API documentation.