Keep your test requests: curl, jq and scripts
Save your API checks as a repeatable script with curl and jq, so one command tells you if the API still works. Postman is optional.
Save your API checks as a repeatable script with curl and jq, so one command tells you if the API still works. Postman is optional.
In plain words
A test request is a question you ask over and over to check the program still answers right. Instead of typing it every time, you write the question and the right answer down once, and a script asks for you.
Try it yourself
Write tests.sh next to app.py. It asks the API a question and fails when the answer is wrong:
#!/usr/bin/env bash
set -euo pipefail
base=${BASE:-http://localhost:8000}
got=$(curl -s "$base/upper?text=hello" | jq -r .upper)
if [ "$got" = "HELLO" ]; then echo "PASS upper"; else echo "FAIL upper: got $got"; exit 1; fi
code=$(curl -s -o /dev/null -w '%{http_code}' "$base/upper")
echo "status without text: $code"
Run it with the API running:
chmod +x tests.sh
./tests.sh
The BASE variable lets you point the same script at another address later.
A step further
set -euo pipefail makes the script stop at the first error instead of carrying on. curl -s hides the progress bar, -o /dev/null -w '%{http_code}' prints only the status code, and jq -r gives a raw value without quotes.
Postman does the same with a window and saved collections. It is an application for your own computer, and it can export its collections as JSON. A script like this one is plain text, lives in Git and runs anywhere, so it is the one to commit.
How it works in real projects
These checks run automatically before a change is accepted. A test framework such as pytest does the same job in Python.