This video is available to students only

Fetching data from a rest API

As stated in the beginning of the course, it's not my intention to teach you every little detail to create a pure React Native app, however connecting your app to a back-end is one of the musts for modern apps, therefore we will go over setting up a store for your network requests. For this I have created a little sample server in Node that we can use to set up a mocked back-end for our app. You can download it here, de-compress it and then in your terminal:

Our sample server#

Let's explore this sample server a bit more. The server is a complete mock implementation - it has no disk persistence, meaning when the server stops, all the data you added to it will be lost. It's configured to start on port 3000 and it exposes two endpoints: GET /book which will retrieve the list of the user's books, and POST /book which will allow the user to create a new entry.

Let's just test it to see what it returns. Once you have started the server, go to your console, there you can run a simple curl command to query the server, it should give us the same objects we had in our store before:

This will query the GET endpoint, which we will use to get the list of books for our user. You should see the following input:

curl output get book

Let's now test the POST endpoint. This endpoint takes a JSON body and will insert it into the in memory array of books:

 

This page is a preview of Building React Native Apps for Mac

Start a new discussion. All notification go to the author.