Episode 7 of 17

Postman

Learn how to use Postman to test your REST API — send GET, POST, PUT, and DELETE requests with custom headers and JSON bodies.

Postman

Testing API endpoints from a browser only works for GET requests. To test POST, PUT, and DELETE, you need a dedicated tool. Postman is the industry-standard API testing tool that lets you send any type of HTTP request, set headers, include JSON bodies, and inspect responses.

What Is Postman?

Postman is a free application for building, testing, and documenting APIs. It provides a graphical interface for crafting HTTP requests — much easier than using the command line or writing test scripts.

Installing Postman

Download Postman from postman.com and install it. You can also use the web version at web.postman.co. A free account is optional but recommended for saving your requests.

The Postman Interface

SectionPurpose
Method dropdownSelect GET, POST, PUT, DELETE, PATCH, etc.
URL barEnter the endpoint URL (e.g., http://localhost:3000/api/ninjas)
Params tabAdd query string parameters
Headers tabSet request headers (Content-Type, Authorization, etc.)
Body tabAdd request body data (JSON, form data, etc.)
Response panelShows the server response (body, status code, headers, time)

Sending a GET Request

Method: GET
URL: http://localhost:3000/api/ninjas
Click "Send"

The response panel shows the JSON data returned by your server, the status code (200 OK), and the response time in milliseconds.

Sending a POST Request with JSON Body

Method: POST
URL: http://localhost:3000/api/ninjas

Body tab:
  → Select "raw"
  → Select "JSON" from the dropdown
  → Enter:
{
    "name": "Ryu",
    "rank": 5,
    "available": true
}

Click "Send"

Postman automatically sets the Content-Type: application/json header when you select JSON as the body format.

Testing All CRUD Operations

OperationMethodURLBody
Get allGET/api/ninjasNone
Get oneGET/api/ninjas/123None
CreatePOST/api/ninjasJSON object
UpdatePUT/api/ninjas/123JSON object
DeleteDELETE/api/ninjas/123None

Organizing with Collections

Postman collections let you group related requests together. Create a collection called "REST API" and add all your ninja endpoint requests to it. Collections can be shared, exported, and documented.

Environment Variables

// Instead of hardcoding:
http://localhost:3000/api/ninjas

// Use a variable:
{{base_url}}/api/ninjas

// Where base_url = http://localhost:3000

Environment variables let you switch between local development and production URLs without editing every request. Create environments for "Development" and "Production" with different base_url values.

Alternative: cURL

# GET request
curl http://localhost:3000/api/ninjas

# POST request with JSON body
curl -X POST http://localhost:3000/api/ninjas \
  -H "Content-Type: application/json" \
  -d '{"name":"Ryu","rank":5}'

# DELETE request
curl -X DELETE http://localhost:3000/api/ninjas/123

cURL is a command-line tool that comes pre-installed on most systems. It is useful for quick tests but Postman is more convenient for complex requests and ongoing development.

Key Takeaways

  • Postman lets you test all HTTP methods — not just GET (which is all a browser can do from the URL bar)
  • Select the method, enter the URL, set the body (for POST/PUT), and click Send
  • For JSON bodies, select "raw" → "JSON" in the Body tab
  • Collections organize related requests; environment variables handle different server URLs
  • The response panel shows the body, status code, headers, and response time