Course outline
cURL to API test ideas
Paste a cURL command; it reads the request and lists the tests worth writing for it, from sign-in to repeats.
Browsers and API tools can copy any request as a cURL command: the method, the address, the headers and the body in one line. That line is also the best start for API tests, because everything worth varying is in it: who is signed in, each field of the body, each query parameter, the method and the content type.
Paste a cURL command. The tool reads the request and lists the tests worth writing for it, grouped by what they check. It runs in this page only: the command, and any token in it, is never sent anywhere. Tokens are hidden in the summary.
Use the tool
Bash (lines ending in \) and Windows (lines ending in ^) commands both work. Nothing you paste leaves this page.
- Method
- POST
- Address
- https://practice.qaia.io/api/coupons/apply
- Authorization
- Bearer YOUR… (hidden)
- Content-Type
- application/json
- Body
{"code":"CEDAR10"}
15 test ideas:
Happy path
- Send it as it is: expect a success status (2xx) and an answer whose fields and types match the documentation.
Sign-in
- Send it without the Authorization header (or the cookie): expect 401, and no data in the answer.
- Send it with a changed or expired token: expect 401.
- Send it with another user's sign-in: expect 403 or 404, never that user's data.
Body fields
- Leave out "code": expect 400 with a message that names the field.
- Send "code" empty (""), and as spaces only: expect 400.
- Add a field the API does not know ("isAdmin": true): expect it ignored or refused, never acted on.
Limits
- Send a very long "code" (10,000 characters): expect 400 or a clear limit, never a 500.
Types
- Send "code" as a number instead of text: expect 400.
Security
- Put markup and SQL text in "code" (<script>, ' OR 1=1 --): expect it refused or stored as plain text.
Body
- Send a body that is not valid JSON (cut it in half): expect 400, not a 500.
Content type
- Send the same body as text/plain instead of application/json: expect 415 or 400.
Method
- Send it with another method (GET instead of POST): expect 405, not a 500 and not a success.
Repeats
- Send it twice, quickly: the change must happen once (a coupon applied once, one order).
Speed
- Time the answer, and send it 20 times in a row: it stays within the agreed time and every answer is the same.
Run it with QAIA: API Analysis reads the same command, writes the tests and runs them.
How the method works
A good API test set starts with the request as it is (the happy path), then changes one thing at a time and checks the status code and the message: no sign-in (401), someone else's sign-in (403 or 404), each required field left out or empty (400), a field of the wrong type, values past their limits, the wrong method (405) and the wrong content type (415).
Two more checks catch the costly bugs. Repeats: the same request sent twice, quickly, must change things once (one order, one discount). Speed: the answer must stay within the agreed time when the request is sent many times in a row. The ideas tell you what to check; the expected status codes come from the API's documentation.
- Copy a request as cURL: in the browser's developer tools (Network, then "Copy as cURL"), or from the API's documentation.
- Paste it here and read the test ideas.
- Write the tests in your API tool, or let QAIA write and run them: "Run it with QAIA" copies the command and opens API Analysis.
A worked example on Cedar Books
Cedar Books applies a coupon through POST /api/coupons/apply (its API docs give the cURL of every call). For that command, the first test ideas are:
| Checks | Test |
|---|---|
| Happy path | Send it as it is: expect a success status (2xx) and an answer whose fields and types match the documentation. |
| Sign-in | Send it without the Authorization header (or the cookie): expect 401, and no data in the answer. |
| Sign-in | Send it with a changed or expired token: expect 401. |
| Sign-in | Send it with another user's sign-in: expect 403 or 404, never that user's data. |
| Body fields | Leave out "code": expect 400 with a message that names the field. |
| Body fields | Send "code" empty (""), and as spaces only: expect 400. |
| Limits | Send a very long "code" (10,000 characters): expect 400 or a clear limit, never a 500. |
| Types | Send "code" as a number instead of text: expect 400. |
The list goes on with types, limits, repeats and speed. Compare each answer with the shop's OpenAPI document: where they differ, you have found a bug. The API tests lab walks through it with QAIA.