How to Test APIs Using Postman: Headers, Environments, and Collections
A developer guide to testing, debugging, and automating API requests using Postman, configuring environment variables, Bearer token headers, and automated test assertion scripts.
Overview #
A developer guide to testing, debugging, and automating API requests using Postman, configuring environment variables, Bearer token headers, and automated test assertion scripts.
Setting Up Your First Request in Postman #
Postman allows developers to craft HTTP calls visually before writing code. To test an API endpoint: select the POST method, enter the endpoint URL, navigate to the 'Authorization' tab to select 'Bearer Token', and enter the raw JSON payload in the 'Body' tab with the format set to JSON.
Managing Secrets with Postman Environments #
Never hardcode API keys into public Postman collections. Create an Environment (e.g. 'Production' or 'Staging') and define an environment variable api_key. In your requests, reference it dynamically with double curly braces: Bearer {{api_key}}.
Automated Status Code & Schema Assertions #
Postman's 'Scripts' tab allows running JavaScript after every request: verify that pm.response.to.have.status(200) and assert that pm.expect(pm.response.json().choices).to.be.an('array') to build continuous integration regression suites.
Code Example: Postman Test Script Asserting Status Code and Latency #
// Postman Post-response Test Script
pm.test("Status code is 200 OK", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is under 800ms", function () {
pm.expect(pm.response.responseTime).to.be.below(800);
});
pm.test("Response contains valid AI completion", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.choices[0].message.content).to.be.a("string");
});
Frequently Asked Questions #
Q: Can Postman test streaming (SSE) endpoints?
Yes, modern versions of Postman natively support Server-Sent Events (SSE) and stream incoming chunks live in the response pane.
Q: How do I share API collections with my team in Postman?
Export your collection as a JSON file or use Postman Workspaces to collaborate with team members in real time.
Q: What is Newman in Postman?
Newman is Postman's CLI runner that allows you to execute Postman test suites inside GitHub Actions or CI/CD pipelines.
Build with API100
Access 100+ AI models through one lightning-fast OpenAI-compatible API with sub-50ms routing overhead and zero markup on cached tokens.

