Asked 24 days ago
28 Dec 2017
Views 107
angeo

angeo posted

how to connect api with react-native in mobile App Development ?

How to connect api with react-native , i used jquery ajax to call server side api untill now for my all javascript web page but dont know how to do ajax call with react-native

using login form so it must use POST method api call
iPhone-coder

iPhone-coder
answered Jan 21 '18 20:17

Use axios ,
install axios by npm command


npm install axios



axios.post('mywebsite.com/login.php', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });



Edit Answer
Share
Mitul Dabhi

Mitul Dabhi
answered Jan 21 '18 20:17

one can use fetch method to call with request object .


var request = new Request("http://mywebsite.com/login.php", {
	method: 'POST',
	mode: 'cors',
	redirect: 'follow',
	headers: new Headers({
		 Accept  : 'application/json',
		'Content-Type' : 'application/json'
	}),
	body :  JSON.stringify ({
		username : 'username',
		password : 'password'
		})
});

// Now use it!
fetch(request).then((response)=>response.json()).
then((res)=>{
console.log(res);
 });

Edit Answer
Share
Post Answer