diff --git a/routes/cars.js b/routes/cars.js index 935c3d3..f7ee842 100644 --- a/routes/cars.js +++ b/routes/cars.js @@ -1,4 +1,28 @@ const express = require('express'); const router = express.Router(); +//Getting information from data/cars.json +const cars = require('../data/cars.json'); + +//Uses res.json to send json and returns it as json +router.get('/', function(req, res, next) { + res.json(cars); //as json array hence res.json + }); + +//GET request that responds with single id entry. +router.get('/:id', function(req, res) { //Get route + let reqID = req.params.id; + const check = cars.find(cars => cars.id == reqID); + + //Checking the id along with if blank + if(!check) { + res.status(200).json({}); + } + else{ + res.send(check); + } + + }); + + module.exports = router; \ No newline at end of file diff --git a/routes/pets.js b/routes/pets.js index 935c3d3..722302d 100644 --- a/routes/pets.js +++ b/routes/pets.js @@ -1,4 +1,32 @@ const express = require('express'); const router = express.Router(); +const petData = require('../data/pets.json'); + +// get all pets +router.get('/', function(req, res, next){ + res.json(petData); +}); + + +// get pets with specified ID +router.get('/:ID', function(req, res, next){ + let id = Number(req.params.ID); + let n = petData.length; + let output = {}; + + console.log(typeof(id)); + console.log(typeof(petData[1].id)); + + for(let i=0; i