Beginner · What full-stack development is · topic 2 of 34 · 30 min
What happens when you tap Save
Explanation
One tap, eight steps
Full-stack work is about connecting the layers, so you must know the whole path of one request. Let us follow a single tap on Save in our Notes app, from the finger to the database and back.
- The click: you tap Save. A JavaScript function in the frontend runs.
- JavaScript builds a request: method POST, address /api/notes, and the note as JSON in the body.
- DNS lookup: the browser turns the name (like notes.example.com) into an IP address, the number that identifies the server on the internet.
- HTTPS connection: the browser and server agree on encryption, so nobody in between (for example on public Wi-Fi) can read or change the data.
- The server route: the backend finds the code for "POST /api/notes", checks you are logged in and checks the title is valid.
- The SQL query: the backend runs an INSERT to store the note, and the database returns the new row.
- The JSON response: the server answers with a status code (201 Created) and the saved note as JSON.
- The screen updates: the frontend reads the JSON and adds the note to your list.
Steps 1 and 2: the click builds a request
JSON (JavaScript Object Notation) is a text format for data, written like a JavaScript object: { "title": "Exam dates" }. Both sides understand it, so the frontend and backend use it to talk. The browser function fetch sends the request.
async function saveNote(title, body) {
const res = await fetch('/api/notes', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, body, pinned: false }),
});
const note = await res.json();
return note;
}Steps 3 and 4: finding the server and locking the line
DNS (Domain Name System) is like the contacts app on your phone: you tap a name, and it finds the number. Browsers and your internet provider remember recent answers, so this step is often instant. HTTPS is HTTP (the language of web requests) with encryption added. The padlock in the address bar means the connection is encrypted.
Steps 5 and 6: the server route and the SQL query
A route is a piece of backend code linked to one method and path. In Express (the Node.js backend library we use) it looks like this. You will write real routes in module 3; for now, just read it.
app.post('/api/notes', async (req, res) => {
const title = (req.body.title ?? '').trim();
if (title === '') {
return res.status(400).json({ error: { code: 'VALIDATION_ERROR', message: 'Title is required' } });
}
const note = await db.insertNote(req.user.id, title, req.body.body ?? '');
res.status(201).json(note);
});INSERT INTO notes (user_id, title, body, pinned, created_at, updated_at)
VALUES (1, 'Exam dates', 'Maths on 12 March', 0, '2026-03-01 10:00', '2026-03-01 10:00');Steps 7 and 8: the response and the screen
Every response starts with a status code: a three-digit number that says how it went. The first digit tells the group. You will meet these again and again.
| Code | Meaning | When the Notes app uses it |
|---|---|---|
| 200 OK | It worked, here is the data | Loading your notes |
| 201 Created | A new thing was made | Saving a new note |
| 400 Bad Request | Your input is wrong | Empty title |
| 401 Unauthorized | You are not logged in | Session expired |
| 404 Not Found | That thing does not exist | Opening a deleted note |
| 500 Internal Server Error | The server broke | A bug in the backend |
Watch the lesson
What happens when you tap Save · 1/7
What really happens when you tap Save in the Notes app? Let us follow one request.
Prefer a video by a teacher? Find free videos on “what happens when you type a url in the browser dns https http request response explained” on YouTube ↗
In real life: Checking results on a college results site
You type your roll number and press Get result. JavaScript builds a request like GET /api/results?roll=21CS045. DNS finds the server, HTTPS protects your roll number on the way, and the backend route checks the roll number format. It runs an SQL query to find your marks and answers 200 with JSON such as { "name": "...", "marks": [...] }. If the roll number does not exist, it answers 404 and the page shows "Result not found". On results day, thousands of these journeys happen every second, which is why such sites sometimes slow down.
Practice (0/3 done)
Write parseRequest(method, url) that returns { method, path, query } (keys in that order). method must be upper case. path is the part after the domain, without the query string. query is a plain object of the query parameters, with their values decoded. Use the built-in URL class: new URL(url).pathname and new URL(url).searchParams.
The eight steps of a request are named: "click", "build request", "dns lookup", "https connection", "server route", "sql query", "json response", "screen update". Fill ORDER with these names in the correct order, then write orderSteps(steps) that returns a NEW array with the given steps sorted into the journey order. Do not change the input array.
Write statusGroup(code) that returns the group of an HTTP status code: "success" for 200-299, "redirect" for 300-399, "client error" for 400-499, "server error" for 500-599, and "unknown" for anything else.
Quick quiz
Read more (free)
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.