01 · Resources & URLs
/garments identifies a collection. /garments/1 identifies one garment. Use nouns for resources and HTTP methods for actions.
Change a request. Send it. See what happens.
// Click Send to call the live learning API.
| ID | Name | Description |
|---|
A client asks for a resource. The server processes that request and returns a representation, usually JSON. Here, our resource is a garment.
/garments identifies a collection. /garments/1 identifies one garment. Use nouns for resources and HTTP methods for actions.
GET reads. POST creates. PUT updates. DELETE removes. These map to CRUD: Create, Read, Update, Delete.
JSON carries data between client and server. A Content-Type header tells the server how to interpret the body. JSON keys need double quotes.
200: success. 201: created. 400: invalid input. 404: resource missing. 409: conflicting name. The body explains the result.
Each request supplies what the server needs to understand it. Stateless does not mean the database forgets data. This lab sends your browser’s isolated catalogue with every request.
Repeating an idempotent operation has the same intended effect. GET, PUT and DELETE are idempotent; repeated DELETE can return 404 after the first deletion. POST is not generally idempotent, although this API returns the existing item for duplicate names.
Teaching detail: the supplied PUT handler replaces the editable fields (name and description). Missing description becomes null. It does not implement PATCH.
Get a separate copy of the supplied Flask + SQLAlchemy + SQLite project. Extract the ZIP, open the BCU folder in your editor, and open a terminal there.
Open http://127.0.0.1:5000/garments on your machine. Edit app.py, save it and send another request.
Use requests.http with VS Code REST Client, import postman_collection.json into Postman, or run python client_demo.py in a second terminal.
The hosted lab is a Cloudflare JavaScript adapter matching the supplied Python API’s teaching behaviour. Its dataset is stored in your browser, sent to the server for each request and returned after changes. It does not run Flask or SQLite. SQL traces are illustrative. Downloaded Python runs the real SQLite database.