Giter Club home page Giter Club logo

lab-11-12-mongo-backed-express's Introduction

cf lab 11 single resource express/mongo api

To Submit this Assignment

  • fork this repository
  • write all of your code in a directory named lab- + <your name> e.g. lab-duncan
  • push to your repository
  • submit a pull request to this repository
  • submit a link to your PR in canvas
  • write a question and observation on canvas

Build Tool Instructions

  • create a package.json that lists all dependencies and developer dependencies
  • include an .eslintrc
  • include a .gitignore
  • add the string db to a new line in your gitignore file so that you dont include the db directory monogd is storeing its files in!
  • create a gulpfile
  • have a lint task for running eslint
  • have a test task for running mocha
  • have a nodemon task that restarts your server any time a change has been bade to your .js files
  • have a default task for running the lint and mocha tasks

Directions

  • Create these directories to organize your code:
  • db - use the command mongod --dbpath ./db to start mongod using this directory
  • lib
  • model
  • route
  • test
  • Create a HTTP Server using express
  • Use the app-error module and error-response middleware from the labs 09-10 for error handeling
  • Create a Simple Model that using mongoose.Schema and mongoose.model
  • The model can represent what ever data you choose. e.g. note, blog post, store items
  • create a lib module named <simple-model-name>-crud.js in your lib directory
  • it should have methods for doing CRUD oppertions of your model
  • it should store your data in mongo using mongoose
  • use the body-parser express middleware to on POST and PUT routes
  • use the npm debug module to log the functions being executed in your app
  • using the express Router create a route for doing RESTFUL CRUD operations on your Simple Model
  • each route should use your lib/<simple-model-name>-crud.js module to manage your model's CRUD opperations

Server Endpoints

/api/simple-model-name

  • POST request
  • pass data as stringifed json in the body of a post request to create a resource

/api/simple-model-name/:id

  • GET request
  • pass the id of a resource though the url endpoint to req.params to fetch a simple-model
  • PUT request
  • pass data as stringifed json in the body of a put request to update a resource
  • DELETE request
  • pass the id of a resource though the url endpoint to req.params to delete a simple-model

Tests

  • your tests should start your server when they begin and stop your server when they finish
  • write a test to ensure that your api returns a status code of 404 for routes that have not been registered
  • for each test setup and teardown mock data using the lib/<simple-model-name>-crud.js module before you make a request
  • write tests to ensure your /api/simple-model-name endpoint responds as described for each condition below:
  • GET - test 200, response body like {<data>} for a request made with a valid id
  • GET - test 404, responds with 'not found' for valid request made with an id that was not found
  • PUT - test 200, response body like {<data>} for a post request with a valid body
  • PUT - test 400, responds with 'bad request' for if no body provided or invalid body
  • PUT - test 404, responds with 'not found' for valid request made with an id that was not found
  • POST - test 400, responds with 'bad request' for if no body provided or invalid body
  • POST - test 200, response body like {<data>} for a post request with a valid body
  • DELETE - test 204, with no body, for a request with a valid id
  • DELETE - test 404, responds with 'not found' for valid request made with an id that was not found

Bonus

  • 2pts a GET request to /api/simple-model-name/all should retrun an array of stored resources

lab-11-12-mongo-backed-express's People

Watchers

James Cloos avatar yun joo kim 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.