REST APIs — Complete Guide
REST APIs — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of Node.js Tutorial on Toolliyo Academy.
On this page
REST APIs
This lesson covers REST APIs. Let us learn this step by step — no rush, no jargon first.
What you will learn
- What rest apis means — in normal words, not textbook words
- How it works step by step
- Code you can run today on your laptop
- Where teams use this in real projects
Before you start
- Software: Node.js LTS from nodejs.org, VS Code, and a terminal
- Knowledge: Earlier lessons in this Node.js course
- Previous lesson: Enterprise MVC Architecture — Complete Guide
Explain it simply
REST is a style for HTTP APIs: use URLs for resources and HTTP methods for actions — GET to read, POST to create, etc.
Why developers use this
- Standard way mobile and web apps talk to servers
- Easy to test with curl or Postman
- Maps cleanly to CRUD
How it works (step by step)
- Client sends HTTP method + URL + optional JSON body.
- Server validates input — reject bad data with 400.
- Business logic reads or writes the database.
- Response is JSON with a clear message the frontend can show.
Code example — type this yourself
app.get('/api/tasks', (req, res) => res.json(tasks));
app.post('/api/tasks', (req, res) => {
const task = { id: Date.now(), title: req.body.title };
tasks.push(task);
res.status(201).json(task);
});
Return JSON with res.json. Use 201 Created after POST. Keep a tasks array in memory for practice.
What each part does
app.get('/api/tasks', (req, res) => res.json(tasks));— Sends the response back to the client.app.post('/api/tasks', (req, res) => {— Defines what happens when a client hits this URL and HTTP method.const task = { id: Date.now(), title: req.body.title };— Line 3: runs as written.tasks.push(task);— Line 4: runs as written.res.status(201).json(task);— Line 5: runs as written.});— Line 6: runs as written.
Real life: where REST APIs shows up
A mobile app talks to a Node backend using REST APIs. The phone sends JSON; the server validates, saves to PostgreSQL, and returns clear success or error messages.
Try it yourself — hands-on
- Add a tasks array
- Test GET with browser or curl
- POST JSON with curl -d '{"title":"Learn Node"}' -H "Content-Type: application/json"
Common mistakes (avoid these)
- Using GET to delete data — use DELETE method instead.
Interview note
Be ready to explain REST APIs with a real trade-off: what problem it solves and what you would not use it for.
Summary
- GET reads, POST creates
- Use proper status codes
- Send JSON with Content-Type application/json
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!