Free tech learning for everyone, from basics to pro

APIsProgramming and Application SecurityBeginner

Testing APIs with Postman and curl

In short: curl sends HTTP requests from the command line and is perfect for quick checks and scripts. Postman is a graphical client that saves requests in collections, uses environment variables for hosts and tokens, and can run simple tests. Use both to understand an API before you automate it.

Why test by hand first

Before you write a Python script against an API, you want to know three things: does the endpoint answer, what does it need, and what does it send back. A manual client lets you change one thing at a time and see the result immediately. Testing by hand also produces something useful for colleagues: a curl command you can paste into a ticket, or a Postman collection the whole team can reuse.

Only test APIs you own or are authorised to use, ideally a lab system or vendor sandbox. Even read-only requests can count as unauthorised access on someone else’s system.

curl vs PostmancurlCommand line, everywhereEasy to scriptCopy into ticketsNo saved workspacePostmanGraphical clientCollections and variablesTests on responsesShareable with team
Figure 1. curl is ideal for quick checks and scripts; Postman is better for exploring an API and saving organised requests.

curl essentials

curl is installed on Linux, macOS and current Windows. These options cover most API work:

OptionMeaning
-X POSTSet the method (GET is the default)
-H "Name: value"Add a header
-d @file.jsonSend a body from a file
-sSilent: hide the progress bar
-i / -vShow response headers / full exchange for debugging
-w "%{http_code}"Print the status code
--fail-with-bodyExit with an error on 4xx/5xx but still show the body
# read a list of devices and pretty-print with jq
curl -s -H "Authorization: Bearer $NMS_TOKEN" \
     -H "Accept: application/json" \
     "https://nms.example.com/api/v1/devices?site=london" | jq '.[] | {name, ip}'

# create a VLAN from a JSON file and show only the status code
curl -s -o /dev/null -w "%{http_code}\n" -X POST \
     -H "Authorization: Bearer $NMS_TOKEN" \
     -H "Content-Type: application/json" \
     -d @vlan30.json \
     https://nms.example.com/api/v1/vlans

Tip: avoid -k (insecure), which turns off certificate checks. If a lab device uses a private certificate authority, point curl at it with --cacert lab-ca.pem instead.

Postman essentials

Postman is a popular graphical API client; open-source alternatives such as Bruno and Insomnia work in a similar way. Key ideas:

  • Collections group related requests, such as Devices, VLANs and Users, in folders.
  • Environments hold variables like {{base_url}} and {{token}}, so one collection works against lab and production by switching environment.
  • Authorisation tab sets bearer tokens, basic auth or OAuth 2.0 for a whole collection.
  • Tests are small JavaScript checks that run after each response, for example that the status is 200 and the reply contains a list.
  • Code generation turns a working request into curl or Python, a quick start for scripts.
pm.test("status is 200", () => pm.response.to.have.status(200));
pm.test("returns a list", () => pm.expect(pm.response.json()).to.be.an("array"));

Mark token variables as secret, keep them in the current (local) value rather than the shared value, and check what you sync to any cloud workspace. A collection exported with a live token is a leaked credential.

A safe API testing routineRead docsendpoint,auth, bodyTry GETread-onlyfirstCheck statusand headersInspect bodyfields andtypesSave requestcollection orscript
Figure 2. Test an unfamiliar API from read-only calls upwards, checking status and body each time before moving on.

Troubleshooting checklist

  1. No response or timeout: check DNS, routing, firewall rules and the port (curl -v shows where it stops).
  2. Certificate error: the client does not trust the server’s certificate. Fix trust; do not disable verification.
  3. 401: token missing, expired or sent in the wrong header.
  4. 403: authenticated but lacking a role or scope.
  5. 400 or 415: body is invalid JSON or Content-Type is missing.
  6. Results look short: look for pagination fields such as next or offset.

At work, a short curl command in a change ticket is a clear record of what was tested. In interviews, being able to explain each curl option shows you understand HTTP rather than just clicking buttons.

Practice

Which curl option would you add to see the response headers as well as the body?
-i (include headers). Use -v for the full request and response exchange including TLS details.
Why use Postman environments rather than typing the host and token into each request?
Variables let one collection work against different systems, and keep secrets in one place that is not hard-coded into every request.
A colleague suggests adding -k to fix a certificate error. What should you do instead?
Find out why the certificate is not trusted and supply the correct CA with --cacert, or fix the server certificate. -k removes protection against man-in-the-middle attacks.

Key takeaways

  • Test by hand before you automate, and only on systems you are allowed to use.
  • curl -H adds headers, -d sends a body, -i/-v show headers and the exchange.
  • Postman collections and environments make requests reusable and shareable.
  • Never disable certificate checks; trust the right CA instead.
  • Keep tokens out of exported collections and shared workspaces.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.