In this workshop we look at how to create an API that keeps track of energy drink consumption.
The API should be able to do a few things:
- return which energy drinks can be consumed
- return a list of all the days of the week - ordered by Monday to Sunday
- return which energy drinks are consumed for a given day of the week
- return which day of the week the most energy drinks are consumed
- return which energy drink is the most popular
- return a list of all the week days and how much energy drinks are consumed for each day
- return how many of a given energy drink were consumed on a given day
- return how many of a given energy drink were consumed for a selection of days
- return a list of all the enery drink consumed for a given day of the week
- return a list of all the enery drink and how many were consumed for a given day of the week
- record that a given energy drink was drank on a given week day
- create a new energy drink that can be consumed
Note: The API can be extended to return nutritional information for a given drink. Can you go and find this information for us. This would supply very interesting information to our API users.
We will focus on these API endpoints initially:
- return which energy drinks can be consumed
- return a list of all the days of the week - ordered by Monday to Sunday
- return which energy drinks were consumed for a given day of the week
- record that a given energy drink was drank on a given week day
URL route | HTTP Type | Parameters |
---|---|---|
/api/energy_drinks |
GET | none |
/api/days |
GET | none |
/api/energy_drink |
POST | drink_id & day_id |
/api/energy_drinks/day/:week_day_id |
GET | day_id |
We will use the CRUD app to get going with the API.
We will need 3 tables. During the workshop we will discuss which fields each table will need.
create table energy_drink (
);
create table week_day (
);
create table drinked (
);
To find images for our energy drinks - 1 can images only.
- PostgreSQL
- REST Client
- express.json - to make POST routes work
- CORS - CORS to enable us to call the API from GitHub Pages and beyond
A VS Code plugin we can use to call API endpoints.