<font class="popmake-631">Subscribe</font>Subscribe with Androidlift to get new post on mail.

Make HTTP Requests With React Native

HTTP requests

The Facebook documentation for React Native have a tutorial for getting movie data from a remote API.  However, it hardly explained how to customize the HTTP request.  In fact, I found that a lot of the internet articles has missed clear cut documentation for RESTful requests with React.

This article should clear things up!

Going forward I’m going to assume that you have a React Native application set up that you can use as your API endpoints.  It doesn’t really matter how you’ve set it up as long as there is a GET endpoint and a POST endpoint.  My endpoints are going to return the following data:

Alright, now that the API stuff is out of the way, let’s see how to hit those endpoints with React Native.

We’re going to be making use of the fetch function.  It can be better understood as follows:

Note :- that the body option will not exist for GET requests.



Let’s start for the project, i assumed you have setup the React-Native for your running platform.for windows platform check this post.

Using your command prompt execute the following :

In your newly created project, open the index.android.js file and replace all code with the following:

Alternatively copy this code to your index.ios.js file and run project on ios simulator.

To run the project make sure your NPM ( React-Native Package Manager) is started. Otherwise start is by using following command. First navigate to your android folder from command prompt.

That sit run your project you will see output as follows.

That sit..we are done here ..Enjoy coding..!