The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

React Native: Using fetch to load external API data

React Native: Using fetch to load external API data

6:26
The way you make HTTP requests in React Native is with fetch. In this video, we'll add integration with the github API into our app using fetch.
Watch this lesson now
Avatar
egghead.io

The way you make HTTP requests in React Native is with fetch. In this video, we'll add integration with the github API into our app using fetch.

Avatar
Sam

How would you go about appending a header to your request?

The approach that I took was: https://gist.github.com/samuelcouch/5d2b860a11f395f250a0

But all I get is an error that says "Can't find variable Headers" referencing line 4.

Avatar
Sam

...Preemptively posted this... Found the solution after looking in to Headers source. It just builds an object for you.

In reply to Sam
Avatar
valentin

When I link the api component to the main.js, I get a surprising message error: Requiring unknown module "../Utils/api". If you are sure the module is there, try restarting the packager. What does it mean to restart the packager ?

Avatar
Lars Jägare

In the video there is a sentence that fetch is not available in the browser yet. But there are polyfills if you want to use the same code in browser as in react-native, e.g. [[https://www.npmjs.com/package/isomorphic-fetch]]

In reply to egghead.io
Avatar
Tyler

Good advice. Ironically, Chrome started supporting fetch a few days after these videos came out too.

In reply to Lars Jägare
Avatar
Anders

I think the "back-tick templating thingy" is known as "interpolation"

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?