Giter VIP home page Giter VIP logo

diy-api's Introduction

DIY API

Deliverable:

It's time to make your own API!

Using what you have learned about Express, Express Routing, RESTful routing, CRUD operations, and Sequelize, use the Sequelize ORM to implement full CRUD functionality on a model (subject of your choosing).


Requirements:

  1. Choose a model that you'd like to build an api about! The model you choose to use should have at least three fields, as well an id field.

Example:

column name type
id integer
createdAt timestamp
updatedAt timestamp
name text
wodgets integer
quantity integer
  1. Your API should be accessible via five routes:
Method Nickname URL Functionality
GET index /widgets list all widgets
POST create /widgets add a widget
GET detail/show /widgets/:id show one widget
PUT update /widgets/:id update one widget
DELETE delete /widgets/:id delete one widget
  1. Move these routes into their own controller, and mount that controller in your main server file.

Steps to Achieve

You will need to:

  1. Fork and clone this repository!
  2. Run npm init to start your node project.
  3. Create a .gitignore and add everything to ignore
  4. Set up Sequelize, create your tables & models
  5. Set up your Express App, create your routes

Recommended Workflow:

  1. Declare your model and migrate.
  2. Stub out your routes, write them res.send("test") for initial decleration.
  3. Link your model to your server.
  4. Update your routes and make the magic happen!

Bonus:

Add a second model to your API. This model should be a parent to your first model via a 1:M relationship. For example: if your first model was books, your second model might be libraries. A library would haveMany books, and each book would belong to 1 library.

Add these new routes:

Method URL Functionality
GET /parents list all parents
GET /parents/:id show a single parent
POST /parents create a new parent
GET /parents/:id/children list all children of the parent with the given id
POST /parents/:id/children create a new child that belongs to the parent with the given id

Get these routes working in your main server file first. Then, once they're working, move them into their own controller, and mount that controller in your main server file.

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.