Prompt

How do I test a REST API with collections and assertions?

Technology / Testing & QA3 observationsLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

A common way to test a REST API is to use an API client like Postman or Insomnia and organize requests into collections with built-in assertions.

Basic workflow

  1. Create a collection

    • Group related requests together, such as:
      • Users
      • Authentication
      • Orders
  2. Add requests

    • Examples:
      • POST /login
      • GET /users
      • PUT /users/:id
      • DELETE /users/:id
  3. Set variables

    • Use environment or collection variables for reusable values like:
      • baseUrl
      • token
      • userId
  4. Write assertions

    • Assertions verify that the API response is what you expect.

Common assertions to check

  • Status code
    • Example: 200, 201, 204, 401, 404
  • Response time
    • Ensure the API responds within a limit
  • Response body
    • Check specific fields and values
  • Headers
    • Validate content type, auth headers, etc.
  • Schema
    • Confirm the response structure matches expectations

Example assertions in Postman

1. Status code

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

2. Response time

pm.test("Response time is less than 500ms", function () {
    pm.expect(pm.response.responseTime).to.be.below(500);
});

3. JSON field value

pm.test("User name is correct", function () {
    const jsonData = pm.response.json();
    pm.expect(jsonData.name).to.eql("Alice");
});

4. Header validation

pm.test("Content-Type is JSON", function () {
    pm.response.to.have.header("Content-Type");
    pm.expect(pm.response.headers.get("Content-Type")).to.include("application/json");
});

Example collection flow

Request 1: Login

  • Send credentials to POST /login
  • Assert 200 OK
  • Extract token:
const jsonData = pm.response.json();
pm.environment.set("token", jsonData.token);

Request 2: Get profile

  • Use token in header:
    • Authorization: Bearer {{token}}
  • Assert:
    • 200 OK
    • Profile contains expected user details

Running collection tests

  • Use the collection runner in Postman to execute all requests
  • Run them in sequence if later requests depend on earlier ones
  • Review failed assertions to find issues quickly

Best practices

  • Keep tests small and focused
  • Reuse variables instead of hardcoding values
  • Validate both success and error responses
  • Test edge cases and invalid inputs
  • Add collection-level pre-request scripts or tests for reusable logic
  • Version your collections if the API changes

If you want automation

You can also run collections from CI/CD using:

  • Newman for Postman collections
  • pytest + requests in Python
  • RestAssured in Java
  • Jest + supertest for Node.js

If you want, I can show you:

  1. a Postman collection example, or
  2. how to do this in JavaScript/Python automation.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (3 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.