Spunk Autos

Websites and web tools

Quick Start: Testing an API

API testing means sending requests to an endpoint and checking that the response is correct. You can start with a single command and grow into automated suites. This quick start suits anyone maintaining a small API, such as the endpoint behind a service-booking form.

Step 1: send a request from the terminal

curl is installed on most systems and is enough for a first test. curl -i https://api.example.com/health prints the status line, headers and body. Add -X POST, -H "Content-Type: application/json" and -d '{"name":"test"}' to send data. Use -w "%{http_code} %{time_total}\n" to print the status code and total time.

Step 2: decide what correct means

A test needs expectations written down before you run it. For each endpoint list:

  • The expected status code for success and for each failure case.
  • Required fields in the response and their types.
  • Headers that matter, such as Content-Type and cache headers.
  • Behaviour with missing or invalid input.
  • Behaviour without credentials or with the wrong user.
  • An acceptable response time.

Step 3: choose a tool type

Tool typeStrengthLimit
Command line (curl, HTTPie-style tools)Fast, scriptable, no install on most machinesAssertions need extra scripting
GUI API clientSaved collections, environments, easy for non-developersTests can drift away from the code
Test framework in your languageLives with the code, runs in CINeeds programming
Contract or schema testingChecks responses against an OpenAPI schemaOnly as good as the schema

A practical path is a GUI client or curl while exploring, then tests in the project's own language once behaviour settles.

Step 4: test the unhappy paths

Most bugs live in error handling. Send an empty body, a wrong type such as text where a number belongs, an expired token, a record ID that does not exist, and a request that conflicts with existing data, such as two bookings for the same slot. Each should return a clear status code and a useful error body, never a 500.

Step 5: look at timing properly

Average response time hides slow outliers. Use the median and a high percentile instead.

Step 6: run it automatically

Put the tests in the repository and run them on every pull request against a test environment. Use separate credentials and test data so a test never touches real customer bookings. Keep secrets in the CI secret store, not in saved collections that might be shared or exported.

Mistakes to avoid

  • Testing only against production data that changes under you.
  • Asserting on the whole response body, so any new field breaks the test.
  • Leaving API keys inside exported collection files.
  • Ignoring rate limits and getting your own IP blocked during a load test.