July 2017
Intermediate to advanced
374 pages
8h
English
In order to integrate our microservices with webViews, we will use AJAX to make API calls.
We need to add the following code snippet in main.js to pull our entire tweet list:
componentDidMount() {
var self=this;
$.ajax({url: `/api/v2/tweets/`,
success: function(data) {
self.setState({tweets: data['tweets_list']});
alert(self.state.tweets);
return console.log("success");
},
error: function() {
return console.log("Failed");
}
});
Similarly, we need to modify our addTweet function in our main.js as follows:
addTweet(tweet){ var self = this; $.ajax({ url: '/api/v2/tweets/', contentType: 'application/json', type: 'POST', data: JSON.stringify({ 'username': "Agnsur", 'body': tweet, }), success: function(data) ...Read now
Unlock full access