Simple Flask endpoint design and implementation
Submit in your repo in the file individual/api.py
This is an INDIVIDUAL assignment. Work on it on your own.
Goals
- Practice designing a simple API endpoint.
- Practice refactoring existing code (in this case, your CLI assignment from Friday) into a new form.
- Practice using python's
flaskmodule.
Rubric
1 - files are named and located as specified
2 - /help endpoint correctness and quality
5 - correctness and quality of your endpoint
What to do
- Remind yourself of the question you focused on for your CLI assignment. You're going to write code to answer that same question, but this time, your user will use a browser to access the data via an API endpoint.
- Design an endpoint for your question, and write documentation for
your endpoint in the "REQUEST/RESPONSE" style you see if you run my
flask_sample.pyand point your browser to/help. - Implement your endpoint in a Flask app. This will mostly involve copying the guts of your CLI assignment over to this new file, and just invoking that same code in a slightly different way. The output to your new endpoint should be in JSON form.
- Implement a
/helpendpoint that shows the documentation for your other endpoint. - Put your tiny 2-endpoint API in
your git repository at
individual/api.py. Also, make sure your data files remain in thedata/directory as in the CLI assignment.
How we will test your work
You can easily run the exact same test the grader and I will run to see whether your see how you have done.
Fire up your Flask app.
[setup and activate our own venv] cd your-repo/individual python3 api.py localhost 9999- Open a browser and go to http://localhost:9999/help to read your documentation.
- Based on the documentation, go to your endpoint to get the interesting data.
Advice
- Do not hesitate to copy my
flask_sample.pyfile to form the basis of this assignment. You can put a brief citation at the top of the file. Cut out stuff you're not going to need (e.g., all that movie data and the movies endpoint, notably). - Work iteratively: change and test one small thing at a time. Start, say, with
a
@app.route('/')with a hello string just to make sure your basic Flask app is working. Then code (and test)/help. etc. - Have fun!