Last active
November 19, 2020 18:25
-
-
Save TheArhaam/3f71a1cd4f5ef0a06c1093adc6815566 to your computer and use it in GitHub Desktop.
randomlist list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const router = require("express").Router(); | |
let Item = require("../../models/item.model"); | |
// POST - Add new item to list | |
router.post("/item", (request, response) => { | |
Item({ name: request.body.item }).save() | |
.then((item) => { response.status(200).json("Item Added Successfully!"); }) | |
.catch((err) => { response.status(400).json("Unable to add item: " + err); }) | |
}) | |
// GET - Fetch entire list | |
router.get("/", (request, response) => { | |
Item.find() | |
.then((list) => { response.status(200).json(list); }) | |
.catch((err) => { response.status(400).json("Unable to fetch list: " + err); }) | |
}) | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment