- The file must be called server.js
- There is a package.json included with dependencies in it, you should know what to do.
- It must use express, and body parser (Set up the app and use the body parser)
- You will want to require the included
users.json file
var users = require('./users.json');
- At the bottom of the file you must
module.exports
your express app. - Listen on port 3000.
Create the following endpoints in server.js
using express.
- Every endpoint will be using the users collection, found in
users.json
. - Each endpoint in this readme is followed by the path that will be tested. For example, 'Get all users.' will be tested by doing a
GET
request to/api/users
. - You can test your work by running
npm test
in your CLI. - When you are finished, you should have
11 tests passed
. - Be sure to use the correct method (GET, POST, PUT, or DELETE) and the correct path (i.e.
/api/users
). - All responses must return a status of 200, unless otherwise specified
-
Get all users. Return all users from the users array.
GET: /api/users
-
Get all users by language. You will receive the
language
as a query ('english, french, spanish or klingon.'). Return an array of all users that have the same language specified in the query.GET: /api/users?language=klingon
-
Get all users, filtering by privilege. You will receive the privilege as a url parameter. ('admin, moderator, user'). Return an array of all users with the same privilege specified in the parameter.
GET: /api/users/admin
-
Find one user by id. Use the url params to get the id. Make sure that a get request for a user that does not exists returns 404.
GET: /api/users/
+ userId -
Create a new user. You will receive the data on the body. All users will need an id property. Manage the value so that it increments each time. Collections should be initialized with a defualt array. Return a valid status code and the new user object you created (with the id on it).
POST: /api/users
-
Create a new admin user. You will receive their privilege as a url parameter. ('admin, moderator, or user'). Return a valid status code and the new user object you created. Make sure to set the privilege correctly.
POST: /api/users/admin
-
Change a user's language. The language will be sent in the body
{language: "New language"}
. Update the user in your array and then return a valid status code and the updated user object.POST: /api/users/language
+ userId -
Add to a users favorite forums. Use params to get a user by id. You will receive the data on the body
{add: 'New Forum'}
. Return a valid status code. #5 must be working in order for this test to pass.POST: /api/users/forums/
+ userId -
Remove from a users favorite forums. Use delete REST method. You will receive the user id in the url params. You will receive the forum to delete in the query. You will need to search your array and splice it out.
DELETE: /api/users/forums/
+ userID +?favorite=
+ forum name. -
Ban (delete) a user. Use REST method delete and the query params to delete a user by their id number.
DELETE: /api/users/
+ userID -
Change your get all users (#1) endpoint so that it uses queries. Allow queries for age, language, city, state, and gender. Note that queries are case sensitive, i.e. ?city="scranton" will not match "Scranton" on the user's city property.
-
Update one user by id. (You'll need to find your user then use a for in loop to update properties). This test will not work if your GET endpoints are not all functioning.
PUT: /api/users/
+ userId