O'Reilly logo

React Native Cookbook by Crysfel Villa, Stan Bershadskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving data from a Remote API

In previous chapters, we've been using the data from a JSON file or directly defined on the source code. While that has been working for our previous examples, it's not what we should do in real-world applications.

In this recipe, we will learn how to request data from an API. We will fetch a GET request from a Heroku API to get a JSON response. For now, however, we are only going to display the JSON in a text element.

This app will be really simple. We will have a text component where we are going to display the response of the API. We will also add a button to request the data when pressed.

Getting ready

We need to create an empty app, in this case, we'll name it RemoteApi. Feel free to use any other name; just ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required