Skip to content

Instantly share code, notes, and snippets.

@ferdelamad
Created August 1, 2018 02:40
Show Gist options
  • Save ferdelamad/cfb73150ae17f32a3f33ddfe7dddaaba to your computer and use it in GitHub Desktop.
Save ferdelamad/cfb73150ae17f32a3f33ddfe7dddaaba to your computer and use it in GitHub Desktop.
FEC - API Call
//Reacting start API Call
componentDidMount () {
let path = window.location.pathname;
path = path.split('/')[2];
const self = this;
axios.get(`/api/restaurant/${path}`)
.then((response) => {
self.setState({
data: response.data,
loaded: true,
viewData: response.data.foodMenu[0].menu
}, () => console.log('HEY THERE'));
});
}
//Server get method
app.get('/api/restaurant/:id', (req, res) => {
getData(req.params.id, (err, results) => {
if (err) {
throw err;
}
res.send(JSON.stringify(results));
});
});
/////DATA FROM THE SERVER
/*
_id : 5b60b04e12bb9509696deb6d
resName : "Nightbird"
foodMenu : Array
drinksMenus : Array
id : 0
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment