← Flask learning pathFlask · Module 7 of 10
Building REST APIs
Return JSON and design clean API endpoints.
📖 Key ideas
- Return dicts or jsonify(data) to send JSON.
- Use HTTP methods for CRUD: GET, POST, PUT/PATCH, DELETE.
- Return proper status codes and error JSON.
- abort(404) stops with an error; errorhandler customises it.
- Flask-CORS enables cross-origin calls from front-ends.
💡 Real-life example: An API is a menu for programs: each endpoint is a dish they can order.
jsonifyCreates a JSON response
abort()Stops with an HTTP error
errorhandlerCustom error responses
Flask-CORSAllows cross-origin requests