In this challenge, you will write an API that can be used to manage Zoos stored in a Relational Database.
Follow these steps for starting your project.
- Fork this repository and clone your fork.
- Add your project manager as collaborator on your fork.
- Create a new branch: git checkout -b
<firstName-lastName>
. - Implement the project on your newly created
<firstName-lastName>
branch, committing changes regularly. - Push commits: git push origin
<firstName-lastName>
.
Follow these steps for completing your project.
- Submit a Pull-Request to merge
<firstName-lastName>
Branch into master (student's Repository). Please don't merge your own pull request - Add your project manager as a reviewer on the pull-request
- Your project manager will count the project as complete by merging the branch back into master.
- Configure
knex
to connect to the/data/lambda.db3
database using thesqlite3
npm module. - Write a set of endpoints inside
index.js
to satisfy the specifications listed below. Feel free to extract the endpoints to it's own express Router. - To start the API, type
npm run server
. - Use a rest client like Insomnia or Postman to test your API.
The included database has a zoos table with the following schema:
Column | Data Type | Details |
---|---|---|
id | integer | primary key, auto-increments |
name | text | required, unique |
When the client makes a POST
request to this endpoint, a new zoo should be created in the zoos table.
Ensure the client passes a name
property in the request body. If there's an error, respond with an appropriate status code, and send a JSON response of the form { error: "Some useful error message" }
.
Return the inserted zoo and a 201 status code.
When the client makes a GET
request to this endpoint, return a list of all the zoos in the database. Remember to handle any errors and return the correct status code.
When the client makes a GET
request to /api/zoos/:id
, find and return the zoo associated with the given id
or an HTTP status code 404
and a helpful message if no zoo with that id
exists. Remember to handle errors and send the correct status code.
When the client makes a DELETE
request to this endpoint, the zoo that has the provided id
should be removed from the database.
When the client makes a PUT
request to this endpoint passing an object with the changes, the zoo with the provided id
should be updated with the new information.
Add a new bears table to the database and add endpoints to perform CRUD operations on it. Each bear should have an id
and name
property similar to the zoos table.