Lesson 31/100

Tutorials Node.js Tutorial

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
Lesson 31 of 100 · Module 4: REST APIs & Databases · INTERMEDIATE
Topic: REST APIs · Level: INTERMEDIATE · Read time: ~15 min + hands-on

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

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.

Think of it like this: A REST API is like a waiter with a menu: GET brings info, POST creates something new, PUT updates, DELETE removes — same rules every time.

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)

  1. Client sends HTTP method + URL + optional JSON body.
  2. Server validates input — reject bad data with 400.
  3. Business logic reads or writes the database.
  4. 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

  1. Add a tasks array
  2. Test GET with browser or curl
  3. POST JSON with curl -d '{"title":"Learn Node"}' -H "Content-Type: application/json"
Tip: Version APIs with /api/v1/ when you ship to real users.

Common mistakes (avoid these)

  • Using GET to delete data — use DELETE method instead.
Pro tip (intermediate): In team projects, document how your team uses REST APIs in the README so new developers onboard faster.

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

Continue learning

Previous: Enterprise MVC Architecture — Complete Guide

Next: CRUD Operations — Complete Guide

Lesson 31 of 100 · Node.js Tutorial

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Node.js Tutorial
Course syllabus

Node.js Tutorial

Module 1: Node.js Foundations
Module 2: Async Programming
Module 3: Express.js & EJS
Module 4: REST APIs & Databases
Module 5: Real-Time & Event Systems
Module 6: Advanced Node.js
Module 7: Performance & Security
Module 8: Testing & Deployment
Module 9: Latest Node.js Features
Module 10: Enterprise Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details