Description
You have enough tools now to create a simple back-end server. In this
assignment you’ll do just that, and post your project to your GitHub repo. We
haven’t gone over all of the moving parts in class yet, so you’ll need to do a little
research on your own. If you get stuck, post a note on Piazza.
Requirements
1. Build a Node/Express application. The app must have:
a. An instance of express.Router in a separate route file that is mounted on
the path /ps3 (i.e. app.use(‘/ps3’…)). If you are using express-generator or
Webstorm to set up an empty project, you’ll find example routes in the
/routes folder. Probably the easiest approach is to modify one of those
files, just be sure to mount it in a different spot.
b. A route using the GET method that returns a fixed string, which can be
anything that you like. The response should be a JSON object with one
key/value pair, such as {string: ‘Hey now’}, passed into a Pug template for
rendering. Your Pug page design is up to you, I would suggest keeping it
really simple. Use the same template for all three problems — Pug provides
conditional statements to hide/show values.
c. A route using the POST method that returns a similar response as b.
above but gets its parameter from the request body rather than the URL
string. (To test this from Postman, select POST as the method, then click
the Body tab. Your input parameter should be an x-www-form-urlencoded
string.) The response should be a JSON object with two key/value pairs,
one for the original string and the second for the length. Pass the object
into a Pug template for rendering.
d. A route using the GET method that reads its input parameter as a named
value on the URL, for example http://localhost:3000/names/Bob, where
Bob is the param. Grab the param and pass it in a JSON object to Pug for
rendering (you should be able to use the same template as in c.).
2. To submit your assignment, drag-and-drop the following files from your project
into Gradescope:
– app.js
– your Pug template(s)
– the route file holding your routes (ps3.js)