Giter VIP home page Giter VIP logo

assignment--fullstack-js-06-rest-api's Introduction

Full Stack JS Project - Rest API Routes

fullstack-js-06-rest-api

Context

You are going to build a full stack web application with node.js + React. In order to become familiar with how a node project works, you will be responsible for configuring the initial major components of the project.

  • express server
  • application routes
  • views
  • api layer
    • data access [this assignment]
    • data models + relations (ORM)
    • RESTful routes

The Assignment

A REST API is a recommended architecture for declaring routes that allows us to interact with a resource (Jobs, Companies) in a predictable + consistent manner.

The goal of this assignment is to create the following REST routes + appropriate database interactions for the jobs + company resources in your apiRouter.js:

GET   -  `/api/jobs`     - Fetches all the jobs
GET   -  `/api/jobs/:id` - Fetches a single job
POST  -  `/api/jobs`     - Creates a job
PUT   -  `/api/jobs/:id` - Edits a job
DELETE - `/api/jobs/:id` - Deletes a job

GET   -  `/api/companies`     - Fetches all the companies
GET   -  `/api/companies/:id` - Fetches a single company
POST  -  `/api/companies`     - Creates a company
PUT   -  `/api/companies/:id` - Edits a company

Requirements

In order to complete this assignment, you will need to:

  • Install body parser

    • you will be sending json to your server in the request body and body parser will allow your express server to read/parse JSON in the request body
    npm install --save body-parser
  • Configure body parser as application middleware

    • in server.js
    const bodyParser = require('body-parser')
    
    //...
    app.use( bodyParser.urlencoded({ extended: false }) )
    app.use( bodyParser.json() )
    
    // ^^ ... before your app routers in express
    // app.use('/', pageRouter)
    // app.use('/apiRouter', apiRouter)
  • Declare routes and create Route Handlers in apiRouter.js

    • you will need to use the following
      • .get(...)
      • .post(...)
      • .put(...)
      • .delete(...)
  • Inside route handler functions for .get(...), .post(...), .put(...), .delete(...) routes, you will need to use Objection's table queries to fetch/create/edit/delete the records in the database

  • Use Postman Request Client to test requests/routes

Expected Results

  • When I send a GET request to http://localhost:3000/api/jobs, the application should:

    • query the job records table and send them to the client as JSON data
  • When I send a GET request to http://localhost:3000/api/jobs/[:\_id]

    • query the job records table for the job with id column value of '_id' from the route.
  • When I send a POST request to http://localhost:3000/api/jobs and JSON in the body, the application should:

    • create a new record in the database
    • send back the new record as JSON to the client (note: the new record will have an id value)
  • When I send a PUT request to http://localhost:3000/api/jobs/[:\_id] and JSON in the body, the application should:

    • edit the record in the database
    • send back the edited record as JSON to the client
  • When I send a DELETE request to http://localhost:3000/api/jobs/[:\_id], the application should:

    • i should send back the following JSON to the client

Setup Instructions

In Terminal:

# (1) navigate to your project--devjobs directory
cd ~/muktek/assignments/project--devjobs

# (2) Commit your changes from the previous demo
git add .
git commit -m 'committing work from part-05-models'

# (3) You will work on the part-06-rest-api branch for this feature
git checkout -b part-06-rest-api

Adventure Mode

Create the DELETE route for companies. To make this work, you will need query and delete the related jobs that have the companyId as a foreign key.

DELETE - `/api/companies/:id` - Deletes a company (and it's jobs)

assignment--fullstack-js-06-rest-api's People

Contributors

tphdev avatar

Watchers

James Cloos avatar  avatar Enrique Carral Trevino avatar

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.