Today, we're going to take a look at the index.js fetch() function. This is where we fetch the data using a POST request.
Axios is the npm package that we will use to make POST requests.
TODO #1: Make an index.js file within /src/services/api
TODO #2: Copy the code in the video to your index.js file
AsyncStorage: Basically, like cookies for react native, it allows us to save our tokens for use later.
url+endPoint: url is retrieved from api_url() in our constants.js file and with endPoint it will form something like https://production.dancingnomads.com/...
token: token is set when user logs in, it is the token used to authenticate the user and make sure that the user is verified to access the data requested.
The fetch() uses a Promise and axios to asynchronously return the response/error retrieved from the API. It is handled accordingly by the function THAT CALLED fetch().
If you look closely, you'll notice that const options REALLY just returns the parameters formatted in axios form.
Use console.log accordingly, to log out what responses/errors you get from your API.
That's all for today!
Don't like to watch videos? Check out our medium post: / react-native-tutorial-step-13
Don't forget to like, comment, and subscribe!
========================================================
Reference Links
========================================================
axios: https://www.npmjs.com/package/axios
react-axios: https://www.npmjs.com/package/react-a...
promise: https://developer.mozilla.org/en-US/d...
========================================================
Connect with me!
========================================================
Linkedin: / donaldlee50
Instagram: / donlee50
Twitter: / donaldlee50
Youtube: / coursehack
Mailing List: http://bit.ly/coursehack-mailing-list
Coursehack's Facebook Group: bit.ly/join-coursehack-facebook-group
Don't forget to like, comment, and subscribe!