Test Locally
Verify endpoints with curl/Postman.
Overview
It’s time to try the API! In this step you will send requests to your running NestJS server and check how the database changes. We use curl/HTTPie examples, but you can follow along with Postman if you prefer a visual interface.
- Make sure
npm run start:devis still running; the server must be up. - Confirm MongoDB is available (Docker container running or Atlas URL configured).
1. Create a task
Choose the command that matches your tool and OS:
http POST http://localhost:3000/tasks \
title="Write tutorial" description="Draft the NestJS guide"Expected response (201 Created):
{
"_id": "6659f0f58f2a3f0f21c1b74d",
"title": "Write tutorial",
"description": "Draft the NestJS guide",
"done": false,
"createdAt": "2025-05-28T12:34:56.789Z",
"updatedAt": "2025-05-28T12:34:56.789Z",
"__v": 0
}Copy the _id value—it’s the MongoDB identifier we’ll use in later steps.
2. List tasks
http GET http://localhost:3000/tasksYou should see an array with the task you just created. If the array is empty, double-check that POST succeeded.
3. Get a single task
http GET http://localhost:3000/tasks/<ID_FROM_PREVIOUS_STEP>If you replace <ID_FROM_PREVIOUS_STEP> with an ID that does not exist, the API returns a 404 with the message Task <id> not found.
4. Update a task
http PATCH http://localhost:3000/tasks/<ID> done:=true5. Delete a task
http DELETE http://localhost:3000/tasks/<ID>"The server responds with 204 No Content. If you try to delete again, you’ll get a 404—exactly what we want.
6. View data in MongoDB
-
mongosh "mongodb://localhost:27017/tasks" --eval 'db.tasks.find().pretty()' -
MongoDB Compass (GUI): connect using the same URI and view the
taskscollection.
Testing with Postman (optional)
- Open Postman and create a new request.
- Choose the HTTP method (POST/GET/PATCH/DELETE) and paste the URL.
- For POST/PATCH, select “Body → raw → JSON” and paste the JSON payload.
- Send the request and inspect the response.
Troubleshooting
| Issue | Possible fix |
|---|---|
ECONNREFUSED | Server not running. Start it with npm run start:dev. |
connect ECONNREFUSED 127.0.0.1:27017 | MongoDB not running (start Docker or check Atlas). |
Task <id> not found on POST | Maybe you’re hitting PATCH/GET with wrong ID—recopy from POST response. |
Validation error (title must be text) | Ensure the request body matches the DTO requirements. |
If everything works, you now have a functioning REST API! Continue to Debugging Basics for tips on solving common issues, then visit Next Steps for ideas on where to go from here.