Created
August 1, 2018 02:40
-
-
Save ferdelamad/cfb73150ae17f32a3f33ddfe7dddaaba to your computer and use it in GitHub Desktop.
FEC - API Call
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
//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