Mongo CRUD
Assignment 2
Due before our week 8 class.
Counts for 10% of your final grade.
The brief
This is the second of three take home assignments related to building a backend web service to support a simple class list application called cListR.
In the previous assignment you built the base for the cListR RESTful API using Node.js and the Express framework. For this assignment you will enhance that base application to use MongoDB for data persistance and add measures to sanitize incoming data.
Core Requirements
Using the Express.js framework, the API will expose a full set of CRUD routes (six, including both
put
andpatch
) for each of two resources: students, and courses. All API resource paths must begin with/api
.Resource collections will be stored in MongoDB and accessed via Mongoose Model classes. The
Model.schema
for the resource objects will have the following properties.
Student
Property | Type | Required | Max Length |
---|---|---|---|
firstName | String | true | 64 |
lastName | String | true | 64 |
nickName | String | false | 64 |
String | true | 512 |
Course
Property | Type | Required | Max Length |
---|---|---|---|
code | String | true | 16 |
title | String | true | 255 |
description | String | false | 2048 |
url | String | false | 512 |
students | Array | false | n/a |
Remember
The MongoDB driver will automatically assign the _id
property.
The
students
property of the Course model should be an array of object ids referencing the Student model.Each resource should have its own Router module.
Routes related to individual members of a resource collection should use a validation function which will return a properly formatted 404 response with an errors array for any invalid
req.params.id
value.All client supplied data (i.e. the
req.body
object) should be sanitized before being stored in the database. This should include guarding against cross site scripting (XSS) and query injection attacks.Ensure that you write clean and readable code. Pay attention to:
- no runtime errors
- consistent 2 space indentation
- logical grouping of related code
- semantically descriptive names for variables and functions
- well organized project folder structure
- properly formatted
package.json
file- correct project name
- your author details
Logistics
- Accept this GitHub Classroom assignment invitation.
- Clone the repo to your laptop.
- Build the project on your laptop.
- Test each route with Postman.
- Make git commits as you complete each requirement
- When everything is complete, push the final commit back up to GitHub and submit the GitHub repo's URL on Brightspace.
TIP
It is a good habit to make a git commit as you complete each logical requirement. This not only tracks your progress, but protects your working code in case you later break it and need to roll back.