You're making an API that can list, create, read, update, and delete a collection of coffee. The problem is that you're missing a critical part of the API-- the database! Create a database for this API, and interface with it via Knex.js.
Make a local database and setup a knexfile
to connect to it.
Make a migration that creates the following database table:
coffee
key | name | data type |
---|---|---|
PK | id | auto-incrementing integer |
name | text | |
roaster | text | |
aroma | integer |
Seed your database with some data:
field | value |
---|---|
id | 1 |
name | Black and Tan |
roaster | Ink |
aroma | 3 |
field | value |
---|---|
id | 2 |
name | Holiday Roast |
roaster | Starbucks |
aroma | 9 |
field | value |
---|---|
id | 3 |
name | House Quake |
roaster | Denver Coffee |
aroma | 6 |
Make sure your next auto-incrementing integer starts with 4
!
Make a connection to your database in the database-connection.js
file with the appropriate environment data.
Fill out the queries.js
file with the following:
list()
should return a promise that resolves with all of the data in thecoffee
table as an arrayread(id)
should return a promise that resolves with the record with a matchingid
as an objectcreate(coffee)
should return a promise that inserts a coffee object and resolves to the created database record as an objectupdate(id, coffee)
should return a promise that updates a coffee record matchingid
with the data incoffee
and resolves to the updated database record as an objectdelete(id)
should return a promise that removes the record matchingid
and resolves to nothing
Deploy this API. Note that you'll need to create a remote database, run your migration and seeds on it, and connect to it in production and your local database in development.
- You can test your API locally with
npm test
Add a link to your deployed API here. https://boe-knex-2.herokuapp.com/coffees