Careeroza
Testing with curl and Postman
curl Cheat Sheet
| Command | Does |
|---|---|
curl URL | GET, print body |
curl -i URL | also show status line and headers |
curl -s URL | silent (no progress bar) |
curl -H "Accept: application/json" URL | send a header |
curl -X POST -H "Content-Type: application/json" -d '{...}' URL | send JSON (used from the medium level on) |
curl -s URL | jq | pretty-print JSON (install jq) |
Tip: On Windows, use curl.exe in PowerShell (plain curl is an alias for Invoke-WebRequest there), or use Git Bash.
Postman
- Create a Collection called "ShopEase".
- Create an Environment with variable
baseUrl = http://localhost:8080. - Add a request:
GET {{baseUrl}}/api/productsand click Send. - Check the status (200 OK), time, and the JSON body in the "Pretty" tab.
- Save every request in the collection; share it with your team or export it as JSON.
GET {{baseUrl}}/api/products [ Send ]
-------------------------------------------------------------
Status: 200 OK Time: 24 ms Size: 412 B
Body Pretty
[
{ "id": 1, "name": "Boat Rockerz 450", "price": 1499.00, ... },
{ "id": 2, "name": "Clean Code", "price": 599.00, ... }
]Browser and IDE
For GET requests, simply open http://localhost:8080/api/products in the browser. IntelliJ IDEA (Ultimate) and the VS Code "REST Client" extension can run .http files stored next to your code:
### All products
GET http://localhost:8080/api/products
Accept: application/json
### Health
GET http://localhost:8080/ping