Rest API using Express
- Install dependencies using "npm install"
- Database already contains default seed data
- No need to run "npm run seed"
- Start application using "npm start"
- Use POSTMAN to test the Rest API
- Use the "RESTAPI.postman_collection.json" file to run test cases in POSTMAN
- Use localhost port 5000
- Below under routes are descriptions of how each route and method work
Attributes: firstName, lastName, emailAddress, password, courses (User one-to-many Courses association)
Attributes: title, description, estimatedTime, materialsNeeded, userId (Courses many-to-one User association)
The GET /api/users route returns all properties and values for the currently authenticated User, includeing all courses associated with the user, with a 200 Ok HTTP status code.
The POST /api/users route creates a new user, set the Location header to "/", returning a 201 Created HTTP status code and no content.
The GET /api/courses route returns all courses including the User associated with each course and a 200 Ok HTTP status code.
The GET /api/courses/:id route returns the corresponding course, based on the :id param, including the User associated with that course and a 200 Ok HTTP status code.
The POST /api/courses route creates a new course, sets the Location header to the URI for the newly created course, and returns a 201 Created HTTP status code and no content.
The PUT /api/courses/:id route updates the corresponding course, based on the :id param, and returns a 204 HTTP status code and no content.
The DELETE /api/courses/:id route deletes the corresponding course and returns a 204 No Content HTTP status code and no content.
Users are authenticated before they are allowed to get data on the current user or before the user can create, update, or delete courses.
The custom middleware function authenticates the user credentials from the requests's Authorization header.
If the authentication is successful, the user is added to the Request object and next() is called.
Else if the authentication fails a 401 HTTP status code and generic “Access Denied” message is returned.
The custom middleware authenticates the following routes:
- /api/users GET
- /api/courses POST
- /api/courses/:id PUT
- /api/courses/:id DELETE
