How to Test an API (Browser, curl & Postman)
Before writing app code, test the API. Here are three easy ways โ from pasting a URL to using a proper API client.
‘Testing an API’ means two different things: exploring a third-party API to see how it behaves, and automated testing of code that depends on an API. Both matter.
Exploring by hand
| Browser | Fastest for a GET with no auth — paste the URL. Install a JSON formatter extension. |
| curl | Scriptable, shows exactly what is sent. -i shows response headers, -v shows the whole exchange. |
| Postman / Hoppscotch / Insomnia | GUI clients: save requests, set environment variables, run collections, inspect history. |
| HTTPie | A friendlier curl: http GET api.example.com/data Authorization:"Bearer $KEY". |
| ‘Try it’ console in the docs | Pre-fills auth and shows the generated request. |
# inspect headers and status curl -i "https://api.example.com/v1/data?q=lagos" # see the full request + TLS handshake curl -v https://api.example.com/v1/data -H "Authorization: Bearer $KEY" # pretty-print JSON curl -s https://api.example.com/v1/data | jq .
What to actually check while exploring
- The happy path: a valid request returns 200 and the shape the docs promise.
- Auth failure: no key → 401; wrong scope → 403.
- Bad input: missing required param, invalid value → 400 with a helpful message?
- Not found: a made-up id → 404 (or an empty list — which is it?).
- Rate limit: what do the headers say, and what happens when you exceed it?
- Pagination: how do you get page 2, and how do you know when you’re done?
- Nulls and optionals: which fields can be absent?
Automated tests for code that calls an API
- Don’t hit the real API in unit tests — it is slow, flaky, rate-limited and may cost money or mutate data.
- Mock the HTTP layer:
responses/respx(Python),nock/msw(JS), or a fake server like WireMock or Mocky. - Record real responses once (VCR-style cassettes) and replay them, so your fixtures match reality.
- Test your handling, not the provider: does your code do the right thing on 429, on a 500, on a timeout, on a malformed body, on an empty page?
- Keep a small number of contract / smoke tests that do hit the real API (or its sandbox) on a schedule, to catch breaking changes early.
Simulating failures
Use httpbin or Postman Echo to force specific behaviour: /status/500, /delay/10, redirects, and various content types. Point your client at those to prove your retry, timeout and error handling work before you meet the real thing.
FAQ
What is the easiest way to test a GET API?
Paste the URL into your browser (with a JSON formatter extension) or run curl -s URL | jq. For anything with auth or a body, use Postman, Hoppscotch or HTTPie.
Should my tests call the real API?
Unit tests: no — mock the HTTP calls. Keep a few scheduled smoke/contract tests against the real API or its sandbox to catch upstream changes.
How do I test how my code handles a rate limit or outage?
Point it at httpbin (/status/429, /status/503, /delay/n) or a mock server configured to return those, and assert your retry/backoff logic runs.
What is a contract test?
A test that checks the real API still returns the shape your code expects (field names, types, required fields). Run it on a schedule so a provider change surfaces before your users hit it.
Keep going
Try it on a real API
๐ Explore free public APIs
Hundreds of free APIs, searchable by category, with auth & CORS at a glance.
Browse the directory โ