Full-Stack Development · Tutorial 3 of 5
What Is a REST API? Explained for frontend developers
By the FUTEAC Team · 30 October 2026 · 10 min read · Beginner
In short
A REST API lets programs talk over HTTP. The frontend requests a URL (an endpoint) with a method — GET to read, POST to create, PUT/PATCH to update, DELETE to remove — and the server answers with data, JSON, plus a status code (200, 404). REST is a set of conventions for doing this: nouns in URLs, verbs as methods.
- An API is a contract between programs. It says: ask me at these URLs, in this format, and I will answer in that format. No human clicks anything.
- REST runs on HTTP, which you already use. Every page load is already a GET request; a REST API just uses the same machinery for data instead of pages.
- Endpoints are nouns, methods are verbs.
/api/coursesnames the thing; GET, POST, PUT/PATCH, DELETE say what to do with it. - JSON is the usual envelope, status codes are the verdict. The body carries the data; the code (200, 201, 404, 500) tells you what happened.
- This tutorial feeds the Node & Express API Foundations course (/course/node-express-api-foundations) and the REST APIs (/skill/rest-apis) skill.
Before you start
What is an API, in plain terms?
API stands for Application Programming Interface. Strip the jargon: it is an agreement that lets one program use another program's capabilities without either one knowing the other's internals.
The version you already know: when a weather app shows today's temperature, its programmers did not build weather satellites. They asked a weather *service's API* — "give me the temperature for Dera Ismail Khan" — and the service answered with a number. The app never sees the satellites, the databases, or the models; it only sees the agreed question and the agreed answer.
A web API does this over HTTP, the same protocol your browser uses. Your React components render data — course titles, prices, user names. A REST API is where that data lives and how your frontend asks for it.
What does "REST" actually mean?
REST stands for REpresentational State Transfer — a name nobody needs to memorise, because the idea is simple: the server holds resources, and the client transfers representations of their state.
In plainer terms, REST is a set of conventions for building web APIs, and the conventions are:
- Client–server. The frontend (client) and the data-holder (server) are separate programs. They only communicate through requests.
- Stateless. Each request carries everything the server needs. The server does not remember your previous requests — like a shopkeeper with no memory, served perfectly if every customer states their full order each time.
- Uniform interface. Resources are named by URLs, manipulated with a small fixed set of methods, and represented in a standard format. Learn the pattern once, read any REST API.
- Cacheable. Responses can say "you may reuse this for 60 seconds", so the client does not re-ask for unchanged data.
You do not need to recite these in an interview tomorrow. You need the working summary: REST APIs expose named things (resources) at URLs, you act on them with HTTP methods, and data travels as JSON.

What is an endpoint?
An endpoint is a URL where the API listens. The convention that makes REST readable: endpoints are nouns naming resources, in plural for collections:
| Endpoint | Means |
|---|---|
GET /api/courses | the collection: all courses |
GET /api/courses/1 | one resource: course number 1 |
GET /api/courses/1/lessons | a sub-collection: lessons of course 1 |
Three rules keep endpoints clean:
- Plural nouns, not verbs.
/api/courses— never/api/getCoursesor/api/fetch_all_courses. The verb belongs in the HTTP method, not the URL. - Hierarchy reads left to right.
/api/courses/1/lessonsis "course 1's lessons" — general to specific, like folders. - One resource, one URL. The same course is always at
/api/courses/1, whether you are reading it, updating it or deleting it. What changes is the method, which is the next section.
What do GET, POST, PUT, PATCH and DELETE do?
HTTP methods are the verbs. Five cover nearly everything:
| Method | Job | Example | Typical success code |
|---|---|---|---|
| GET | Read something | GET /api/courses — list courses | 200 OK |
| POST | Create something new | POST /api/courses — add a course | 201 Created |
| PUT | Replace something entirely | PUT /api/courses/1 — replace course 1 | 200 OK |
| PATCH | Update part of something | PATCH /api/courses/1 — change its title | 200 OK |
| DELETE | Remove something | DELETE /api/courses/1 — delete course 1 | 200 or 204 |
Two subtleties beginners trip on:
- GET never changes anything. It only reads. If your "delete" is a GET request with
?action=delete, that is not REST — and it is dangerous, because browsers, crawlers and caches all assume GET is safe to repeat. - POST vs PUT vs PATCH. POST *creates* (the server assigns the new id). PUT *replaces* the whole resource (you send the complete new version). PATCH *modifies* part of it (you send only the changed fields). In practice many APIs use POST and PATCH and rarely PUT — but knowing the distinction keeps you from misusing them.
What does the server send back?
Two things: a status code and usually a JSON body.
Status codes are three-digit verdicts, grouped by their first digit:
| Code | Meaning | When you see it |
|---|---|---|
| 200 OK | It worked | GET and PATCH/PUT succeeded |
| 201 Created | It worked and something new exists | POST succeeded |
| 400 Bad Request | Your request was malformed | Missing field, bad JSON |
| 404 Not Found | No such resource | Wrong id, wrong URL |
| 500 Internal Server Error | The server broke | A bug on their side, not yours |
The habit to build now: read the status code before the body. A 404 with a helpful JSON error is still a 404 — your code must branch on the code, not on parsing the body and hoping.
JSON (JavaScript Object Notation) is the usual body format — objects and arrays as text:
{
"id": 1,
"title": "HTML & CSS Foundations",
"level": "Beginner"
}JSON is a subset of JavaScript object syntax, which is why frontend developers feel at home: JSON.parse() turns it into a real object, JSON.stringify() turns an object back into text for sending.
Worked example: run a real course API on your machine
Everything above becomes concrete in about thirty lines. Save this as server.js — it uses only Node's built-in http module, no packages to install — and run it with node server.js:
const http = require('node:http');
const courses = [
{ id: 1, title: 'HTML & CSS Foundations', level: 'Beginner' },
{ id: 2, title: 'JavaScript Essentials', level: 'Beginner' },
];
const server = http.createServer((req, res) => {
const url = new URL(req.url, 'http://localhost:3000');
if (req.method === 'GET' && url.pathname === '/api/courses') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(courses));
} else if (req.method === 'GET' && url.pathname.startsWith('/api/courses/')) {
const course = courses.find(c => c.id === Number(url.pathname.split('/')[3]));
if (course) {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(course));
} else {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Course not found' }));
}
} else if (req.method === 'POST' && url.pathname === '/api/courses') {
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
const course = { id: courses.length + 1, ...JSON.parse(body) };
courses.push(course);
res.writeHead(201, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(course));
});
} else {
res.writeHead(404, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: 'Not found' }));
}
});
server.listen(3000, () => console.log('listening on 3000'));Now talk to it with curl — a command-line tool for making HTTP requests. Each pair below is the actual output of a real run (Node.js v24, curl 8.5):
Read the collection:
curl http://localhost:3000/api/courses[{"id":1,"title":"HTML & CSS Foundations","level":"Beginner"},{"id":2,"title":"JavaScript Essentials","level":"Beginner"}]
HTTP 200Read one resource:
curl http://localhost:3000/api/courses/1{"id":1,"title":"HTML & CSS Foundations","level":"Beginner"}
HTTP 200Ask for what does not exist — note the 404 arrives *with* a JSON body explaining it:
curl http://localhost:3000/api/courses/99{"error":"Course not found"}
HTTP 404Create a resource — -X POST sets the method, -H sets the JSON content header, -d sends the body:
curl -X POST http://localhost:3000/api/courses \
-H "Content-Type: application/json" \
-d '{"title":"React From Scratch","level":"Intermediate"}'{"id":3,"title":"React From Scratch","level":"Intermediate"}
HTTP 201Run the first GET again and the collection now holds three courses — the POST really stored it (in memory; restart the server and it resets, which is exactly why real APIs use databases — the subject of the Node course).
Expected result: you have made all five kinds of REST conversation happen — list, read one, miss (404), create (201) — against a server running on your own machine. That is what every frontend "loading…" spinner is waiting on.
How does a frontend page call it?
curl was the manual version. In a page, fetch does the same job — here reading the course list into a React-style render:
fetch('http://localhost:3000/api/courses')
.then(res => {
if (!res.ok) throw new Error('HTTP ' + res.status); // read the code first
return res.json();
})
.then(courses => {
courses.forEach(c => console.log(c.id, c.title));
})
.catch(err => console.error('Request failed:', err.message));Expected result (with the server running): the console prints 1 HTML & CSS Foundations and 2 JavaScript Essentials. Three things to notice, because they are the whole frontend-API discipline in miniature: check res.ok (the status code) before touching the body; .json() parses the envelope; .catch() handles the network failing, which is different from the server answering 404.
Try it yourself
With the server running: (1) curl a PATCH-like update by hand is not implemented in this tiny server — instead, add a DELETE /api/courses/:id branch yourself, following the GET-one pattern, and verify it with curl; (2) change the 404 error body to include the id that was requested ({ error: 'Course 99 not found' }); (3) in the fetch snippet, render the courses into actual <li> elements on a page instead of logging them. Each exercise touches one REST idea: methods, error bodies, and consuming JSON in the DOM.
Continue in the free course: Node & Express API Foundations →
Common mistakes
- Verbs in URLs.
/api/getCoursesor/api/deleteCourse/1— the method already says the verb. Nouns in the URL, verbs in the method, always. - Ignoring the status code. Parsing the body without checking
res.okfirst means a 404 error page gets treated as data. Code first, body second. - POST for everything. Using POST to read, update and delete "because it works" throws away the conventions that make APIs predictable — and breaks caching, which only applies to GET.
- Forgetting the JSON content header. A POST with a JSON body but no
Content-Type: application/jsonheader arrives as mystery text; most servers reject it with 400. The header is part of the contract. - Putting secrets in frontend code. API keys pasted into a React component ship to every visitor's browser. Keys belong on a server (yours), never in code the client downloads.
Frequently asked questions
Is REST the only way to build an API?
No — GraphQL and tRPC are popular alternatives, and plain WebSockets suit live data. REST remains the default to learn first because it is the simplest contract: URLs, five methods, JSON, status codes. Everything else is easier once REST is obvious.
Do I need to learn backend development to use a REST API?
No. Using an API (this tutorial) and building one (the next tutorial, with Node and Express) are separate skills. Frontend developers consume APIs daily while never writing a server — but understanding the server's side makes you dramatically better at the frontend side.
What is an API key, and where does it fit?
A secret token that identifies *who* is asking, sent as a header (often Authorization). Public learning APIs skip it; real ones require it so the provider can rate-limit and bill. Rule from the mistakes section: keys live on servers, never in frontend code.
Where does this fit in the Full-Stack Developer roadmap?
It is the bridge between the two halves of the roadmap: you finish the React series knowing how components render data, then this tutorial shows where data comes from, then the next tutorial has you build the server itself with Node and Express. The roadmap's full-stack project — a working app with your own API — starts here. ---
Follow the Full-Stack Developer Roadmap
Build complete web applications — frontend, backend APIs, databases and deployment. Free, step by step, at your pace.
View the Roadmap