It's time to make your own API again!
Using what you have learned about Flask, RESTful routing, CRUD operations, and SQLAlchemy, use the SQLAlchemy ORM to implement full CRUD functionality on a model (subject of your choosing).
- The model you choose to use should have at least three fields, as well an id field.
Example for Widget Model:
column name | type |
---|---|
id | integer |
name | text |
wodgets | integer |
quantity | integer |
- Your API should be accessible via five routes:
Example:
Method | Action | URL | Functionality |
---|---|---|---|
GET | index | /widgets | list all widgets |
POST | create | /widgets | add a widget |
GET | detail/show | /widgets/:id | show one widget |
PUT | update | /widgets/:id | update one widget |
DELETE | delete | /widgets/:id | delete one widget |
You will need to:
- Fork and clone this repository!
- Create your virtual environment
python -m venv venv
- Create a
.gitignore
and add your virtual environment folder. (check out github's suggestions for.gitignore
) - Activate your virtual environment
- Install dependencies
pip install Flask Flask-SQLAlchemy psycopg2
- Copy our installs into a requirements.txt file.
pip freeze >> requirements.txt
- Create a
models.py
file for your models and anapi.py
for your flask server.
Recommended Workflow:
- Stub out your routes
- Write you
models.py
file - Link your model to your server
- Update your routes and make the magic happen!
Add a second model to your API. This model should relate to your first model via a 1:M relationship.
Once added, update your GET and POST routes for this second model which allow you do the following with your API:
- Show all elements from second model that relate to your element from first model at :id.
- Add a new element to your original model that include related elements from this second model at :id.
Make another model and create a N:M relationship!