Topics:
- Relational Databases
- MySQL and SQL Lite
- Query Builders
- Knex
- Create/Read/Update/Delete operations
You'll write a server that lets you create and read Zoos and Bears stored in a Relational Database. Much of the knowledge from Node and Express will carry over to this mini project, where you'll interface with a database in your route handlers.
For this mini sprint you'll need to have SQLite3 and MySQL intalled. MySQL must be running.
- Fork and Clone this project.
cd
into your project folder.- Run
npm install
oryarn
to download the dependencies. - Write your implementation inside
server.js
to satisfy the specifications listed below. - To start the API server, run
npm start
oryarn start
. - Use Postman to test your API.
Create the following tables for the Zoos and Bears collection.
Zoos Table should have the following columns:
- id: primary key, automincrements.
- name: unique, alphanumeric up to 255 characters long.
- created_at: should automatically default to the current date and time.
Bears Table should have the following columns:
- id: primary key, automincrements.
- zooId: an integer that relates this table to the zoos table. Enforce data integrity.
- species: unique, alphanumeric up to 80 characters long.
- latinName: alphanumeric up to 80 characters long.
- createdAt: should automatically default to the current date and time.
When the client makes a POST
request to /api/zoos
a new zoo should be created in the zoos table:
- Ensure the client passes a name parameter 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 de
id
of the inserted zoo.
When the client makes a GET
request to /api/zoos
, return a list of all the zoos in the database.
Remember to handle the errors and return the correct status code.
When the client makes a GET
request to /api/zoos/:id
(remember, :id
is a
parameter embedded in the URL, not in the query-string):
- Find the zoo associated with the given
id
. Remember to handle errors and send the correct status code.