Block 64: Flask: REST API Endpoints
Build a JSON REST API with Flask.
Concepts
- jsonify() to return JSON
- HTTP methods: GET, POST, DELETE on same route with methods=['GET','POST']
- request.get_json() to receive JSON body
- Status codes: 200, 201, 400, 404
Code Examples
See exercise below.
Exercise
Build a simple in-memory 'todo list' API: GET /todos, POST /todos, DELETE /todos/<id>. Test your API using the requests library or a browser.
Homework
What is REST? List its 5 key constraints in your own words. Wednesday