git checkout week1). Create a new git branch week2 and choose it (git checkout -b week2).package.json) installed (npm install).src/items.js
items mock data array from src/index.js to the new module filecreate a new function getItems() in the module and export it
const getItems = (req, res) => {
res.json(items);
}
export {getItems};
import the getItems() function in src/index.js and use it to get the items data by modifying the GET /items endpoint
import {getItems} from './items.js';
...
app.get('/items', getItems);
GET /items/:id and POST /items endpoints (create functions in src/items.js and import and use them in src/index.js)src/items.js. For example:
Create a new module file src/users.js and add the following mock data to it:
const users = [
{
id: 1,
username: "johndoe",
password: "password1",
email: "johndoe@example.com"
},
{
id: 2,
username: "janedoe",
password: "password2",
email: "janedoe@example.com"
},
{
id: 3,
username: "bobsmith",
password: "password3",
email: "bobsmith@example.com"
}
];
users resource using the mock data provided
POST method to create a new userGET method to get a specific userPOST method
users module in src/index.js to register the new endpointsFollow the teacher’s example (“Creating a REST API with mock data” section above, link to the example code is in Oma). Implement TODOs marked in code comments in the teacher’s lecture example code. See assignment details in Oma.