View Code? Open in Web Editor
NEW
This project forked from codefellows-seattle-javascript-401n1/lab-11-12-mongo-backed-express
lab-11-12-mongo-backed-express
JavaScript 46.30%
Shell 53.70%
lab-11-12-mongo-backed-express's Introduction
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
- 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
- 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
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
- 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
- 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