Skip to lesson content
Web Technologies › Level 20
LEVEL 20 · BACKEND

Server-Side Web Programming

Trace a request through trusted checks, business rules and a deliberate response.

🖥️ Backend📨 Requests + responses🔐 Identity + permissions🧪 Lab + MCQs
01

Learning Objectives

Requests

Identify method, path, headers and body.

Routing

Select a handler and reject unsupported operations.

Checks

Validate input and apply identity, permission and capacity rules.

Responses

Return a deliberate status and representation.

02

Where Does the Code Execute?

Separate execution responsibilities
Browser

Display a form and provide immediate feedback.

Request

Carry the requested operation and input.

Backend

Check rules against trusted application state.

Response

Return the result for the browser to display.

Static Resources and Dynamic Responses

Stored file

A stylesheet can be served without constructing its contents per learner.

Catalog API

A handler can return a current list as JSON.

Personal page

A server can render a page from a recognized user’s records.

Mixed application

Static assets and dynamic handlers can work together.

03

Read the Request: Method, Path, Headers and Body

POST /bookings HTTP/1.1
Content-Type: application/json
Authorization: Bearer fixture-learner

{"workshopId":"html","seats":1}
04

Routing — Match the Target Before the Handler

PathSupported methodsRule
/workshopsGETPublic catalog, no mutation
/profileGETRecognized identity
/bookingsGET, POSTOwn records or a validated booking
/admin/reportGETAdministrator only
05

Methods Describe the Intended Operation

// Contract examples — not live calls from this page:
// GET /workshops       -> read current catalog
// GET /bookings        -> read this identity's bookings
// POST /bookings       -> attempt to create a booking
// DELETE /workshops    -> unsupported here: 405
06

Parse Input, Then Validate Its Meaning

const parsed = JSON.parse(rawBody);
// Check exact shape, allowed workshopId and integer seats.
const accepted = validateBooking(parsed);
// A loaded "1" string is not the required numeric 1.
07

A Handler Pipeline with Clear Boundaries

Follow a booking handler
Route

Select POST /bookings.

Identity

Look up the fixture credential.

Input and rules

Validate the record and current capacity.

Commit and respond

Create one booking, then return 201.

08

HTML Templates and JSON APIs

// JSON response concept:
{
  "id": "booking-1",
  "workshopId": "html",
  "seats": 1
}
// A template could instead place these values into an HTML page.
09

Shared Data and Business Rules

// Illustrative SQL shape; bind parameters through the driver.
UPDATE workshops
SET remaining = remaining - :seats
WHERE id = :id AND remaining >= :seats;
// Check affected rows and insert the booking in one transaction.
10

Sessions Connect Requests to an Identity

Recognize a caller
Credential input

A request presents an identifier.

Trusted lookup

The backend validates it against its own rules.

Identity

A recognized user is available to the handler.

Lifecycle

Expiry, logout and revocation need deliberate handling.

11

Authentication and Authorization Answer Different Questions

Who?

Recognize the credential through the trusted lookup.

Allowed?

Apply the route’s permission rule.

Whose record?

Use the recognized user when reading or creating records.

Rejected

Stop before a data operation when a check fails.

12

Status Codes and Useful Failure Responses

Try thisExpected statusState change
GET /workshops as guest200None
POST /bookings as guest401None
GET /admin/report as learner403None
Valid booking of an available place201One booking and reduced remaining count
Valid request for unavailable places409None
13

Security Is More Than Input Validation

// Unsafe design idea:
// authorize(request.body.role === "admin");
// Better boundary:
// recognized = verifyCredential(request);
// requirePermission(recognized, "view-report");
14

Runtime, Configuration and Deployment

Runtime

Execute the server language in a supported environment.

Configuration

Keep private values in the backend’s protected settings.

Contract

Agree on routes, input, statuses and response fields.

Verification

Check real operations, errors and deployed behavior.

15

Connect the Browser to a Tested Backend

Verify one full application flow
Interface

Collect the learner’s requested operation.

Handler

Validate and apply trusted rules.

Data operation

Commit consistently or leave records unchanged.

Outcome

Return and display a deliberate result.

16

Premium Visualizer — A Server Request Pipeline

Follow one accepted booking from request through route, identity, validation and a mock commit. The player uses the same approved five-stage presentation as the earlier lessons. The lab separately exposes the rejection paths.

SERVER REQUEST PIPELINE
Step 1 of 5
STEP 01

Receive the booking request

A client requests one HTML place using the agreed JSON contract.

POST /bookings {"workshopId":"html","seats":1}

What is happening?

This is a local teaching trace. A deployed backend would receive an actual HTTP request.

17

Premium Interactive — Workshop Backend Simulator

GET routes ignore this body. The booking contract accepts only workshopId and numeric seats. Use fictional data; never paste real credentials here.

Idle. No simulated request processed.

Request passed to the local handler

No request yet.

Handler stage trace

No trace yet.

Simulated response · status, headers and JSON body

No response yet.

Mock backend state · visible for teaching

Starting places: HTML 3, CSS 2, JavaScript 0. No bookings.
18

Debugging — Find the First Failed Check

Route or method

404 means unknown target here; 405 includes the supported methods.

Identity or permission

Distinguish an unrecognized caller from a recognized caller without the required role.

Body or rule

Separate JSON syntax, record validation and capacity conflicts.

Commit

A failed operation must not consume places or create a partial booking.

19

Interview Questions — Flip to Explain

QUESTION

Can frontend form validation protect the backend by itself?

Click or press Enter to explain
ANSWER

No. A caller can bypass browser checks. The backend must validate the received data and apply its own rules.

QUESTION

What is the difference between static and dynamic responses?

Click or press Enter to explain
ANSWER

Static content can be served from stored resources; dynamic content is computed from request information and application state. A dynamic application can still serve static assets.

QUESTION

What distinguishes a 404 from a 405 in this lab?

Click or press Enter to explain
ANSWER

404 is an unknown path. 405 is a known path with an unsupported method and includes an Allow header.

QUESTION

Why is an integer quantity still subject to a business check?

Click or press Enter to explain
ANSWER

It may be a valid input but exceed the current remaining places. Validation and capacity rules answer different questions.

QUESTION

What distinguishes authentication and authorization?

Click or press Enter to explain
ANSWER

Authentication recognizes the caller. Authorization decides whether that caller may perform the operation on the resource.

QUESTION

Can a booking body choose its trusted owner or administrator role?

Click or press Enter to explain
ANSWER

No. The handler derives ownership and permissions from the recognized identity, not client-supplied claims.

QUESTION

Why is this browser simulator not a real protected backend?

Click or press Enter to explain
ANSWER

All its code, fixtures and state run in the browser and can be inspected or changed. It teaches a pipeline without implementing a separate server.

QUESTION

What must a real capacity update and booking insert provide?

Click or press Enter to explain
ANSWER

A consistent transaction and concurrency strategy so both succeed together or neither leaves a partial result. The local synchronous exercise does not test database guarantees.

20

MCQ Practice — Trace the Backend Decision

PRACTICE

1. Where must a real backend validate a booking request?

PRACTICE

2. Which route reads the public catalog in this lab?

PRACTICE

3. What does an unknown /missing path return here?

PRACTICE

4. Which response accompanies an unsupported method on a known path?

PRACTICE

5. What does a guest POST /bookings encounter first?

PRACTICE

6. What does a learner GET /admin/report return?

PRACTICE

7. Which JSON seats value meets the numeric contract?

PRACTICE

8. What happens to a valid request when places are insufficient?

PRACTICE

9. Where does the booking owner come from?

PRACTICE

10. What does the injected server failure do here?

PRACTICE

11. Is repeating an accepted POST deduplicated in this lab?

PRACTICE

12. Does the local simulator prove deployed database concurrency safety?

21

Extra Practice — Predict and Verify the Response

Public read

Reset, then GET /workshops as guest. Expected: 200; remaining 3/2/0 and no bookings.

Missing identity

POST /bookings as guest with valid JSON. Expected: 401, Bearer challenge, no mutation.

Wrong role

GET /admin/report as learner, then as admin. Expected: 403 followed by 200.

Routing

Try GET /missing and DELETE /workshops. Expected: 404, then 405 with Allow: GET.

Body validation

As learner POST /bookings with malformed JSON, seats "1" or an extra role. Expected: 400, no mutation; text/plain gives 415.

Create

As learner POST HTML/2. Expected: 201; HTML remaining 1, one booking owned by user-1.

Conflict or failure

Request HTML/2 again: 409. Then request HTML/1 with server failure: 500. Expected: remaining stays 1.

Ownership and reset

  • GET /bookings as learner and admin.
  • Expected: each sees its own records.
  • Reset: all fixtures restored and mock bookings cleared.
22

Quick Revision

Execution: Browser and backend have different responsibilities.
Responses: Static assets and computed content can coexist.
Request: Read method, path, headers and body.
Route: Match explicit allowed operations.
Validate: Parse syntax, then check record meaning.
Identity: Recognize a caller through trusted rules.
Permission: Check role and resource ownership.
Commit: Keep shared records consistent.
Status: Describe success and the failed stage clearly.
Scope: A local simulation is preparation for deployed testing.
23

Glossary — Flip to Learn

TERM

Backend

Click to see meaning
DEFINITION

Backend

The application environment that executes server-side logic and produces responses.

TERM

Dynamic response

Click to see meaning
DEFINITION

Dynamic response

Content computed using request information and application state.

TERM

Route

Click to see meaning
DEFINITION

Route

A mapping from a request target and allowed method to a handler.

TERM

Handler

Click to see meaning
DEFINITION

Handler

Code that processes an accepted request and constructs its outcome.

TERM

Middleware

Click to see meaning
DEFINITION

Middleware

Shared processing that runs around or before route-specific handler work.

TERM

Authentication

Click to see meaning
DEFINITION

Authentication

Establishing the caller’s identity under the application’s rules.

TERM

Authorization

Click to see meaning
DEFINITION

Authorization

Deciding whether a recognized caller may perform an operation on a resource.

TERM

Session

Click to see meaning
DEFINITION

Session

Application state associated with a recognized request identity and its lifecycle.

TERM

Transaction

Click to see meaning
DEFINITION

Transaction

A coordinated data operation that commits or rolls back related changes together.

TERM

Idempotency

Click to see meaning
DEFINITION

Idempotency

A property where repeating an operation has the same intended effect as performing it once.

24

Final Challenge — Specify a Real Booking Service

25

Level 20 Complete?

Before marking complete, trace a successful booking and reproduce route, identity, permission, body, capacity and pre-commit failure outcomes. Explain how the real backend would differ from this teaching simulation. Completion is a local study marker, not a verified assessment.