SlideShare a Scribd company logo
1 of 43
React Developer
Digital Talent Scholarship 2022
Session 08: Data Fetch
Welcome!
Anyone ever heard about
API?
● List
● API
● Axios
Agenda
Install Postman
List
Let’s create a beautiful movie list!
● https://pastebin.com/y3sfrWWS
● Copy the file and save as fetchedMovies.json in src/data folder
● From this list, we will only show poster, year, title, and rating(for now!)
● Now, let’s load and display our data!
We’ll be using Surfaces > Card > UI Controls as
our base
Checkout to branch 01-add-navbar
https://github.com/depimomo/react-tmdb-movie
Clone this for your guide 👍
Create MovieCard.js under component like this!
Just hardcode the data
Card width 400px
Image size => width: 150, height: 225
Hint: Use MUI Rating!
Create MovieList.js
under container and
load multiple
MovieCard, style it to
look nicely
Putting it all together
● Load JSON file in MovieList using
○ import fetchedMovies from './data/fetchedMovies.json';
○ In React, you don’t need to read file manually using fs!
● After loading data, store data to a state called movies.
○ Only store the array in results field!
● Pass the movie data one by one using map to MovieCard props
● At MovieCard, load the data from props then display it!
MovieList
Result so far
Load images
● To load images, you can use poster_path from JSON
● You need to add this:
○ https://image.tmdb.org/t/p/original
○ As the prefix before poster path
○ For example:
https://image.tmdb.org/t/p/original/7ucaMpXAmlIM24qZZ8uI9hCY0hm.jpg
● Create const called BASE_IMAGE_URL at the top of MovieCards, then prepend it
when you try to load the image
Load images
Result so far
Checkout to branch 02-movie-cards
https://github.com/depimomo/react-tmdb-movie
Clone this for your guide 👍
API
What is API?
● API is the acronym for Application Programming Interface, which is a software
intermediary that allows two applications to talk to each other.
● In this case, we will working with REST API
What is REST API?
● REST APIs communicate via HTTP requests to perform standard database
functions like creating, reading, updating, and deleting records (CRUD)
● HTTP Method: GET: retrieve record(s), POST: create record(s), PUT: update a
record, DELETE: delete one
Install and using Postman
What is Postman?
● Postman is an API platform for building and using APIs. Postman simplifies each
step of the API lifecycle and streamlines collaboration so you can create better
APIs—faster.
● Here, you can do all HTTP Method and get the result
Using our first API
● Go to https://www.themoviedb.org/ and create an account
● Go to Settings > API to get your API Key (v3 auth). This is like your password to
access their API
● Then, go to https://developers.themoviedb.org/3/getting-started/introduction to learn
more about their API
Using our first API
Open in Postman
HTTP
Method
Query Param
URL
Get result!
We will using “trending/movie/week” endpoint.
Try it out in postman!
Axios
What is Axios?
● One of the fundamental tasks of any web application is to communicate with
servers through the HTTP protocol.
● Axios is a Javascript library used to make HTTP requests.
How to use Axios?
Axios response schema
● Unlike Postman, Axios will
wrap the response in “data”
field
● Therefore, we must add .data
when accessing the results
Modify MovieList into this
Since we already prepare MovieCard to load
data according to it’s props, we don’t have to
change anything else! 🤩
Checkout to branch 03-simple-axios
https://github.com/depimomo/react-tmdb-movie
Clone this for your guide 👍
Axios instance
Axios instance
Axios instance
Checkout to branch 04-axios-instance
https://github.com/depimomo/react-tmdb-movie
Clone this for your guide 👍
Stop for a little, read official docs,
articles and keep coding.
At the end, you know what you
did. You should be able to
explain someone else about what
you learn.
References
beta.reactjs.org
axios
mui.com

More Related Content

Similar to 08 - Data Fetch (Monica).pptx

Similar to 08 - Data Fetch (Monica).pptx (20)

Mojolicious
MojoliciousMojolicious
Mojolicious
 
APIs for modern web apps
APIs for modern web appsAPIs for modern web apps
APIs for modern web apps
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
solution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptxsolution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptx
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Web Scrapping Using Python
Web Scrapping Using PythonWeb Scrapping Using Python
Web Scrapping Using Python
 
Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Offline of web applications
Offline of web applicationsOffline of web applications
Offline of web applications
 
Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014Offline for web - Frontend Dev Conf Minsk 2014
Offline for web - Frontend Dev Conf Minsk 2014
 
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksHeadless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles ServiceAraport Workshop Tutorial 2: Authentication and the Agave Profiles Service
Araport Workshop Tutorial 2: Authentication and the Agave Profiles Service
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
A Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & DjangoA Gentle introduction to Web Development & Django
A Gentle introduction to Web Development & Django
 

Recently uploaded

Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
 

Recently uploaded (20)

Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Connaught Place ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft DatingDubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 

08 - Data Fetch (Monica).pptx

  • 1. React Developer Digital Talent Scholarship 2022 Session 08: Data Fetch
  • 3. ● List ● API ● Axios Agenda
  • 6. Let’s create a beautiful movie list! ● https://pastebin.com/y3sfrWWS ● Copy the file and save as fetchedMovies.json in src/data folder ● From this list, we will only show poster, year, title, and rating(for now!) ● Now, let’s load and display our data!
  • 7. We’ll be using Surfaces > Card > UI Controls as our base
  • 8. Checkout to branch 01-add-navbar https://github.com/depimomo/react-tmdb-movie Clone this for your guide 👍
  • 9. Create MovieCard.js under component like this! Just hardcode the data Card width 400px Image size => width: 150, height: 225 Hint: Use MUI Rating!
  • 10. Create MovieList.js under container and load multiple MovieCard, style it to look nicely
  • 11. Putting it all together ● Load JSON file in MovieList using ○ import fetchedMovies from './data/fetchedMovies.json'; ○ In React, you don’t need to read file manually using fs! ● After loading data, store data to a state called movies. ○ Only store the array in results field! ● Pass the movie data one by one using map to MovieCard props ● At MovieCard, load the data from props then display it!
  • 14. Load images ● To load images, you can use poster_path from JSON ● You need to add this: ○ https://image.tmdb.org/t/p/original ○ As the prefix before poster path ○ For example: https://image.tmdb.org/t/p/original/7ucaMpXAmlIM24qZZ8uI9hCY0hm.jpg ● Create const called BASE_IMAGE_URL at the top of MovieCards, then prepend it when you try to load the image
  • 17. Checkout to branch 02-movie-cards https://github.com/depimomo/react-tmdb-movie Clone this for your guide 👍
  • 18. API
  • 19. What is API? ● API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other. ● In this case, we will working with REST API
  • 20. What is REST API? ● REST APIs communicate via HTTP requests to perform standard database functions like creating, reading, updating, and deleting records (CRUD) ● HTTP Method: GET: retrieve record(s), POST: create record(s), PUT: update a record, DELETE: delete one
  • 21. Install and using Postman
  • 22. What is Postman? ● Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster. ● Here, you can do all HTTP Method and get the result
  • 23. Using our first API ● Go to https://www.themoviedb.org/ and create an account ● Go to Settings > API to get your API Key (v3 auth). This is like your password to access their API ● Then, go to https://developers.themoviedb.org/3/getting-started/introduction to learn more about their API
  • 27. We will using “trending/movie/week” endpoint. Try it out in postman!
  • 28. Axios
  • 29. What is Axios? ● One of the fundamental tasks of any web application is to communicate with servers through the HTTP protocol. ● Axios is a Javascript library used to make HTTP requests.
  • 30. How to use Axios?
  • 31. Axios response schema ● Unlike Postman, Axios will wrap the response in “data” field ● Therefore, we must add .data when accessing the results
  • 33. Since we already prepare MovieCard to load data according to it’s props, we don’t have to change anything else! 🤩
  • 34. Checkout to branch 03-simple-axios https://github.com/depimomo/react-tmdb-movie Clone this for your guide 👍
  • 38. Checkout to branch 04-axios-instance https://github.com/depimomo/react-tmdb-movie Clone this for your guide 👍
  • 39. Stop for a little, read official docs, articles and keep coding. At the end, you know what you did. You should be able to explain someone else about what you learn.
  • 42. axios

Editor's Notes

  1. https://www.postman.com/
  2. https://mui.com/material-ui/react-card/#ui-controls
  3. https://mui.com/material-ui/react-rating/#basic-rating
  4. https://www.postman.com/
  5. https://developers.themoviedb.org/3/getting-started/authentication#api-key
  6. https://developers.themoviedb.org/3/getting-started/authentication#api-key
  7. https://developers.themoviedb.org/3/getting-started/authentication#api-key
  8. https://api.themoviedb.org/3/trending/movie/week https://developers.themoviedb.org/3/trending/get-trending
  9. https://axios-http.com/
  10. https://axios-http.com/docs/api_intro
  11. https://axios-http.com/docs/res_schema
  12. https://axios-http.com/docs/instance
  13. https://axios-http.com/docs/instance
  14. https://axios-http.com/docs/instance
  15. https://beta.reactjs.org/learn/your-first-component
  16. https://axios-http.com/docs/example