// --------------------------------------------- SERVER CODE --------------------------------------------- //
app.get('/rooms/:id/pictures', function (req, res) {
console.log('hello');
findPicturesByRoomId(req.params.id)
.then(function (images) {
res.send(images.image_url);
});
});
app.get('/:id', function (req, res) {
res.sendFile(path.resolve(__dirname, '../public/index.html'));
});
// -------------------------------------------- DATABASE CODE -------------------------------------------- //
const findPicturesByRoomId = (roomNumber) => {
return PicturesModel.findOne({ room_id: roomNumber }).then((data) => {
return data;
})
}
// ---------------------------------------- POSTMAN GET REQUEST URL ---------------------------------------- //
localhost:4500/rooms/1/pictures
// ------------------------------------------ GET REQUEST RESPONSE ------------------------------------------ //
[
"http://lorempixel.com/640/480",
"http://lorempixel.com/640/480",
"http://lorempixel.com/640/480",
"http://lorempixel.com/640/480",
"http://lorempixel.com/640/480"
]
Last active
December 22, 2018 00:16
-
-
Save mariomui/98dcd729a8a300ce56c484d249f2c87f to your computer and use it in GitHub Desktop.
Example API call
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment