Serve data to programs through REST endpoints, described with OpenAPI.
Lectures this week
- API Design
- REST
- REST APIs – Examples I
- REST APIs – Examples II
- OpenAPI
- Important Concepts of an API
Key points, notes and past questions
REST APIs & Flask-RESTful
JSON endpoints, flask_restful resources and curl.
- Start here: JSON and HTTP for programs, from zero
- An API answers programs with JSON.
- True/None/tuple become true/null/array; keys become strings.
- Flask serialises returned dicts and parses request.json.
- Without Content-Type: application/json, request.json gives 415.
- APIs, SDKs, OpenAPI and documentation
- API = exposed operations.
- SDK contains API libraries and tools.
- OAS = standard description format for REST APIs.
- API docs list endpoints, parameters, responses.
- HTTP methods with curl
- No flag = GET.
-Xsets the method.-d= form data unless a JSON Content-Type header is given.- Methods are upper-cased by Flask.
- JSON responses in Flask
- jsonify and dict returns give JSON, 200.
- Mimetype application/json.
- Lists stay lists.
- Resource classes and method mapping
- Verb → method of the same name.
- Every URL of a resource accepts all its methods.
- Missing method → 405.
- Arguments must match the URL's placeholders, or 500.
- URLs and arguments for resources
- One segment per placeholder; converters filter.
name=valuein a path is just text.- Trailing slash rules still apply (308).
- Method parameters must match the URL.
- reqparse and marshal_with
- reqparse reads named arguments; type converts; required → 400 if missing.
- marshal_with keeps only listed fields and converts types.
- Missing optional arguments are None.
- Caching and status codes
- Caching reduces latency and server load.
- GET is cacheable by default; POST is not.
- 201 Created for a successful POST; 405 for a missing verb; 415 for a non-JSON body.
Notes23 past questions in this topic
Week 5: Controllers & CRUDWeek 7: Backend SystemsAll MAD 1 topics and weeks