Handling API Pagination - Advanced API Testing

Many APIs return large datasets across 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 required pages have been retrieved. Pagination is an important concept in Advanced API Testing, especially when validating APIs that work with large datasets.

A typical paginated request looks like:

Advertisement
GET https://api.example.com/users?page=1&size=10

Here:

  • page specifies which page to retrieve.
  • size specifies 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 can:

  • Check whether a nextPage value exists.
  • Automatically prepare the next page request.
  • Continue processing until no additional pages remain.
  • Validate the complete dataset.

Interview Tip:
"We used Postman scripts to automatically detect the nextPage parameter and continue sending requests until every page was retrieved, allowing us to validate the complete dataset instead of only 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 can reduce over-fetching by returning only the fields requested by the client.

Postman provides built-in support for testing GraphQL APIs, making GraphQL an important area to understand in Advanced API Testing.

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 GraphQL APIs

You can:

  • Validate responses using Postman Test Scripts.
  • Verify returned fields.
  • Check response errors.
  • Validate response status and structure.
  • Debug requests using the Postman Console.

Interview Tip:
"GraphQL allows clients to request only the required fields in a single API call, which can reduce unnecessary data transfer and improve efficiency."


Working with SOAP APIs

SOAP (Simple Object Access Protocol) is a protocol for exchanging structured information using XML-based messages.

Unlike REST APIs, which commonly use JSON, SOAP uses XML for its requests and responses.

Understanding SOAP is useful for testers working on enterprise applications and Advanced API Testing projects involving legacy or XML-based services.

Key Features of SOAP

  • Uses XML for requests and responses.
  • Follows strict messaging standards.
  • Uses WSDL (Web Services Description Language).
  • Structures messages using SOAP Envelopes.
  • Supports standardized communication between applications.

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 inside a SOAP Envelope.
  • Include the required request headers.
  • Add the SOAPAction header when required.
  • Send the request.
  • Validate the XML response.

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 when required, and validate the XML response using Postman Test Scripts."


REST vs GraphQL

Aspect REST GraphQL
Endpoints Multiple endpoints Typically a single endpoint
Response Generally defined by the endpoint Client requests specific fields
Data Fetching May require multiple API calls Can retrieve related data in fewer calls
Over-fetching Can occur Can be reduced
Real-Time Support Usually requires additional mechanisms Supports subscriptions
Best Use Case Straightforward API architectures Complex and data-intensive applications

Example

REST

GET /users/1

The API may return more information than the client requires.

GraphQL

A single query can request only the fields needed by the client.

This can reduce unnecessary data transfer and make data retrieval more efficient.

When to Use Each

  • Use REST for straightforward APIs with predictable resource-based operations.
  • Use GraphQL when clients need flexible, nested, or complex data retrieval.

Mock APIs and Mock Servers

A Mock API simulates the behavior of a real API without requiring an actual backend server.

Postman provides a Mock Server feature that can return predefined responses.

Mock APIs are particularly useful in Advanced API Testing when the actual backend is unavailable or when specific response scenarios need to be simulated.

Why Use Mock APIs?

Mock APIs can help you:

  • Develop APIs before the backend is available.
  • Test frontend applications independently.
  • Simulate expected API responses.
  • Test error handling.
  • Simulate different response scenarios.
  • Validate edge cases.
  • Test applications against predefined data.

Creating a Mock Server in Postman

Follow these steps:

  1. Create a new collection.
  2. Add a request.
  3. Define the mock response.
  4. Open Body → Raw → JSON.
  5. Save the example response.
  6. Open the collection options.
  7. Select the mock server option.
  8. Create a new mock server.
  9. Enter a name.
  10. Save the generated mock URL if required.

A mock endpoint may look similar to:

https://mock-server.postman.com/mock/12345/users

You can send requests to this URL in a similar way to a real API.

Interview Tip:
"We used Postman Mock Servers to allow frontend development to continue even before the backend APIs were fully implemented."


Generating API Documentation

Postman can generate API documentation from a collection.

The generated documentation can include:

  • Request methods
  • URLs
  • Headers
  • Request bodies
  • Parameters
  • Sample responses
  • Example requests

Documentation can be shared with team members or published for API consumers, depending on the project requirements.

Since the documentation is generated from the collection, maintaining the collection properly helps keep the documentation aligned with the API requests.


FAQs

How Do You Handle API Pagination in Postman?

Use page and size query parameters and create a Postman script that processes the nextPage value until all required pages have been retrieved.

You can also validate the records returned from each page and verify that the complete dataset is handled correctly.


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, and then validate the response using Postman Test Scripts.


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 when required, and validate the XML response using Test Scripts.


What Is the Difference Between REST and GraphQL?

REST typically uses multiple endpoints and predefined response structures.

GraphQL generally uses a single endpoint and allows clients to request the specific fields they need.


What Is a Mock Server in Postman?

A Mock Server is a simulated API that returns predefined responses without requiring a real backend.

It allows developers and testers to simulate different API behaviors and test applications before the actual backend is available.


How Do You Generate API Documentation in Postman?

Postman can generate documentation from a collection containing API requests, examples, parameters, headers, and response information.

Keeping the collection updated helps maintain accurate API documentation.


Key Takeaways

  • Pagination allows APIs to return large datasets across multiple requests.
  • GraphQL allows clients to request specific fields instead of receiving a fixed response.
  • SOAP uses XML-based messages and is common in enterprise and legacy systems.
  • Mock Servers allow testers to simulate API responses without a real backend.
  • Postman can help generate and maintain API documentation.
  • These capabilities are valuable for Advanced API Testing and real-world API automation projects.