Giter Club home page Giter Club logo

db-zoos's Introduction

Building an API using a Relational Database Mini

Topics:

  • Relational Databases
  • SQLite
  • Knex
  • Create/Read/Update/Delete operations

Description

You'll write a server that lets you create and read Zoos 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.

Running the Project

  • Fork and Clone this project.
  • cd into your project folder.
  • Run npm install or yarn to download the dependencies.
  • Add knex and sqlite3 npm modules.
  • Configure knex to connect to /data/lambda.sqlite3 using the sqlite3 module.
  • Write a set of endpionts inside index.js to satisfy the specifications listed below.
  • To start the API server, run yarn start or npm start.
  • Use Postman to test your API.

Specifications

Table

The included database has a zoos table with the following schema:

  • id: integer, primary key, autoincrements.
  • name: text, required, unique.

POST /api/zoos

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 id of the inserted zoo and a 201 status code.

GET /api/zoos

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.

GET /api/zoos/:id

When the client makes a GET request to /api/zoos/:id, find the zoo associated with the given id. Remember to handle errors and send the correct status code.

DELETE /api/zoos/:id

When the client makes a DELETE request to this endpoint, the zoo that has the provided id should be removed from the database.

PUT /api/zoos/:id

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.

Stretch Problem

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.