Advanced Web Applications Development

Reference

Reference

Endpoints, status codes, commands, branches and the words used — one page to keep open during the labs.

Everything in one place. Keep this tab open.

Endpoints

Method and path What it does Arrives in Needs a login
GET /api/health Says whether the server and database are up Starter No
GET /api/stops Lists stops for the search form Starter No
GET /api/fares?from=&to= Today’s fare for a route Lab A No
POST /api/fares Adds a fare Lab B Yes, from Lab C
POST /api/login Starts a session, sets the cookie Lab C No
POST /api/logout Ends the session Lab C No
GET /api/me Who the current session belongs to Lab C Yes

from and to are stop ids, not names. Get them from GET /api/stops. In the seed, Westfield is 1 and Brikama is 8.

Status codes

Code Name What it means here
200 OK A read worked
201 Created A fare was added. The Location header says where to read it
204 No Content Logged out. Nothing left to say
400 Bad Request Your input is wrong and you can fix it
401 Unauthorized You are not signed in
404 Not Found No such route, fare, or endpoint
409 Conflict Stretch task: that fare already exists
501 Not Implemented The Lab A stub, before you build it
503 Service Unavailable The server is up but the database is not

Two worth knowing properly:

401 is misnamed. It says Unauthorized but means unauthenticated — we do not know who you are. The code for “we know who you are, and you still may not” is 403 Forbidden. The Lab C stretch task is where that difference starts to matter.

400 and 404 are different fixes. A 400 means the request was wrong, so the sender changes it. A 404 means the request was fine and the thing is missing, so someone has to create it. Collapsing the two is how an API becomes impossible to debug from outside.

npm scripts

Command What it does
npm run dev Starts the server and restarts it on every change
npm start Starts the server
npm run setup Creates the tables, then seeds them
npm run seed Refills the sample data
npm run reset Drops everything and starts again
npm test Runs the tests
npm run db:push Makes the database match the schema

npm run reset is the recovery command. If anything is strange, run it before you debug anything else.

Git commands used

git clone https://github.com/your-username/passo.git
git status
git checkout checkpoint/lab-a-done
git checkout -b my-experiment
git add -A
git commit -m "What I changed"
git push
git log --oneline --graph --all

git checkout <branch> moves you to existing work. git checkout -b <name> makes a new branch from where you are. If you have edits you do not want to lose, commit them first — switching branches with unsaved work is how people lose an afternoon.

Branches

Branch What it holds
main The starting point. Lab A begins here
checkpoint/lab-a-done Fare search finished
checkpoint/lab-b-done Adding a fare finished
checkpoint/lab-c-done Login finished
checkpoint/lab-d-done Tests finished. The full solution
demo/injection Deliberately unsafe. For the briefing only — never merged

Each checkpoint is the end of one lab and the start of the next, so falling behind costs one command:

git checkout checkpoint/lab-b-done
npm run reset

The words

API — the part of the program other programs talk to. Here, everything under /api.

Endpoint — one address the API answers on, such as GET /api/stops.

Route — careful, it means two things in this project. A transport route is a one-way trip between two stops, and it is a table. An Express route is code that answers one endpoint. Context tells you which.

ORM — a layer that lets you work with database rows as objects. Prisma is ours. It writes the SQL so you do not glue strings together.

Schema — prisma/schema.prisma, the description of every table and column. The database is made to match it.

db push vs migration — db push makes the database match the schema and keeps no history. A migration is a numbered SQL file you commit, so changes can be replayed in order on a real server. We use db push because it is a workshop.

Seed — sample data loaded by npm run seed so the app has something to show. Every seeded fare is marked sample.

Parameterised query — a query where values travel separately from the sentence, so input can never be read as a command. Prisma does this for you.

SQL injection — what happens when they are not separate. Searching for ' OR '1'='1 returns every row, because the quote ends the string and the rest is read as instructions.

Hash — a one-way function. scrypt turns a password into something that cannot be turned back. The database stores the hash, never the password.

Salt — random text mixed into each password before hashing, so two people with the same password get different rows.

Session — the server’s memory of who is signed in. The browser holds only a random id in a cookie; everything else stays on the server.

httpOnly — a cookie flag that stops JavaScript on the page reading the cookie, so an injected script cannot steal the session.

Middleware — a function that runs before the handler. requireLogin is one: it either answers 401 or lets the request through.

CI — continuous integration. The GitHub Actions workflow that runs the tests on every push, on a machine that has never seen your laptop.

Idempotent — safe to run twice. npm run seed is. Adding a fare is not.

Saved in this browser only.