Do the following exercises for this homework.
Configure a webserver to store a set of people records (first name, last name, loginID, startDate) where the loginIDs are unique and the start date indicates when the person started with the organization. Hard-code the data using an appropriate JavaScript data structure and serve up JSON-formatted versions of the requested data on the following routes.
/people
- a list of all people objects
/person/id
- the full record for the person with the given ID
/person/id/name
- the full name (i.e., first & last concatenated into one string) for the person with the given ID
/person/id/years
- the seniority (i.e., number of years with the organization) of the person with the given ID — Report this as you would report an age (i.e., rounded down to the nearest whole year).
If the loginID doesn’t exist or if the required data is missing or incomplete, serve up a 404-not-found error.
Here is a useful reference on Express Routing. You’ll need route parameters
and the res.json()
and res.sendStatus()
response methods.
Configure NPM to install the required modules (using npm
install
) and add an NPM “start” script to start
the server. Also, include basic header documentation using JavaDoc format and
add the git ignore file to prevent checking
node_modules/
into your repo.
Submit your solution in GitHub under the homework1
repo.
Submit the files as specified above. We will grade your work according to the following criteria:
Homeworks are always due by the beginning of next Friday’s lab period (e.g., this one is due when lab 5 is due).