Skip to content

Instantly share code, notes, and snippets.

@kdefliese
Created June 12, 2015 05:01
Show Gist options
  • Save kdefliese/c1403481efde23664e83 to your computer and use it in GitHub Desktop.
Save kdefliese/c1403481efde23664e83 to your computer and use it in GitHub Desktop.
// 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