Each standalone app below builds on the previous app(s). The instructions given are only for the current app, with the assumption that you don't need repeat instructions for the previous steps.
Create a package.json file and install/save dependencies (like express, body-parser, etc).
Set up an express server that listens on port 3000.
Create GET
and POST
endpoints for the items array. Send the results with an ok
status code.
Export the data in the data.js file and require it in your index.js file. Create GET
and POST
endpoints for the data and send the results with an ok
status code.
Create CRUD endpoints on the supplied data. You will want to use it, and mimic it's format when adding new data.
-
- Create an endpoint to
GET
all objects.
- Create an endpoint to
-
- Create an endpoint to
POST
a new object.
- Create an endpoint to
-
- Create an endpoint to get one item by index/id. Hint: Use
req.params
- Create an endpoint to get one item by index/id. Hint: Use
- 1b) Update endpoint #1 to look for query parameters and get only matching items.
-
- Create an endpoint to remove an object by index/id. Hint) Use
req.params
- Create an endpoint to remove an object by index/id. Hint) Use
-
- Create an endpoint that can update one object by id. Hint: Use
req.query
to determine which properties to update
- Create an endpoint that can update one object by id. Hint: Use
Use express to serve the static files in the public folder.
Use express sessions to save data to the session using a POST
endpoint and access that saved data using a GET
endpoint.
- Create a top-level middleware function that is used on every request (keyword
USE
). This function can be as simple as logging something to the console.- Create two endpoints to test that your middleware function runs on every request and that the endpoints work properly.
- Create a middleware function that checks to see if there is a current user logged in (see the
login
endpoint to see what happens when someone logs in). If there is no user logged in, end the function with aforbidden
orunauthorized
status code. If there is a user, return next. - Apply that middleware to all routes dealing with
admin
things. - Test your middleware. If you try to hit the admin endpoints without logging in first, you should see an empty response and your
forbidden
orunauthorized
status code. If you log in first, the request will be completed.
If you have time, create a whole front to back app that uses a front end rather than Postman.