Created
June 12, 2015 05:01
-
-
Save kdefliese/c1403481efde23664e83 to your computer and use it in GitHub Desktop.
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
// creating a JSON object that contains all my cats | |
"allMyCats": [ | |
{"name": "Maxwell", "color": "black", "type: "Burmese"}, | |
{"name": "Gracie", "color": "black and white", "type: "American shorthair"}, | |
{"name": "Gizmo", "color": "tabby", "type: "unknown"} | |
] | |
//making a get request at the url "/cats" | |
app.get("/cats", function (req, res) { | |
//picking a random cat from the array | |
var randomCat = allMyCats[Math.floor(Math.random() * allMyCats.length)]; | |
//returning the JSON for that cat | |
res.json(allMyCats[randomCat]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment