How To Make An API Request in ReactJS With Axios and Fetch - Tutorial [2020]

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • In this video I will teach you guys how to use Axios and Fetch to make API Requests. This can be used to fetch data from a public API or any backend you are building. I am teaching you how to to do this in ReactJS.
    API LINK: official-joke-...
    -
    Please leave a comment on what topic you guys want me to cover next!
    -
    👕 Programming Merch: teespring.com/...
    💻 PedroTech Discord: / discord
    -
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Twitter: / pedrotech_
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/mac...
    Email: machadop1407@gmail.com
    Tags:
    Axios
    Fetch
    ReactJS Tutorial
    ReactJS and MySQL
    NodeJS Tutorial
    API Tutorial

ความคิดเห็น • 161

  • @prasanthraonilapu8809
    @prasanthraonilapu8809 3 ปีที่แล้ว +34

    Nice pacing dude, you weren't speed piling information on us and you weren't slowly stretching things out either. I understood it quite well.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      Thank you! Glad you enjoyed it! I always get scared that I am going too fast or too slow hahaha

  • @Scrany99
    @Scrany99 3 ปีที่แล้ว +50

    You are an absolute legent. I've spent the whole day trying to figure out how to do it and this has been the best explained and the most complete explanation I've seen for React based in fuctions and not classes

    • @Scrany99
      @Scrany99 3 ปีที่แล้ว +1

      I have a further question. I have in one file called "fetchCall.js" a fetch call to an API, but I want in another file called "inputTextFilled.js", which is a form, I want to have some prefilled information for some of the parts of the form. How can I make it to be able to import the values from fetchCall.js to inputTextFilled.js?

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Thank you so much for the positive comment! I am glad I could help!

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      You can make the api call from the fetchCall.js and return those by exporting them. Then just call the fetchCall inside the inputTextField and use the values returned.

    • @Scrany99
      @Scrany99 3 ปีที่แล้ว

      @@PedroTechnologies So, to do that I should declare the variable outside the function with a "export const[name,setName] = useState("")" and then in the inputTextField I should do an import {name} from './fetchCall'
      And then just to access the data what should I write? Does it work only writing "name"?

  • @WorkshopMaybe
    @WorkshopMaybe 3 ปีที่แล้ว +10

    Nice explanation in under 10 minutes, thank you!
    And your responses to the jokes had me cracking up, that could be its own youtube series ;)

  • @arhamraza5019
    @arhamraza5019 2 ปีที่แล้ว +3

    Oh god!!!!! after days of struggling for a single concept and getting to know that its this simple.
    Thanks man for this

  • @WeirdStuffaaaa
    @WeirdStuffaaaa 3 ปีที่แล้ว +1

    I watched few tutorials before . They are super fast and not explaining even in a simple details like you . Your videos is very clear . thhanks youuu

  • @lance740
    @lance740 ปีที่แล้ว +1

    Best video covering this that I have found. Thank you so much, most videos are overly complicated and 20 minutes long. This was so straight to the point and explained clearly

    • @Shaojeemy
      @Shaojeemy ปีที่แล้ว

      Was it just me or chatGPT kept switching up the file structure everytime i needed more details for this?

    • @ibesarah3263
      @ibesarah3263 ปีที่แล้ว

      Exactly..well explained and straight to the point.

    • @owofrostyy8840
      @owofrostyy8840 10 หลายเดือนก่อน

      ​@@Shaojeemyit's not ChatGpt it's just he has an extension specifically for React installed in his IDE. All it does is give him hints and fix his React code when needed

  • @knotcircle2844
    @knotcircle2844 4 ปีที่แล้ว +4

    I heard about this Axios from your previous video of ReactJS MySql tutorial. Really helpful for beginners like me on reactjs and axios. Thank you

    • @PedroTechnologies
      @PedroTechnologies  4 ปีที่แล้ว

      I am glad you liked it! When I first tried to learn fetch I thought it was weird, when I saw axios it made so much more sense!

  • @jhconger
    @jhconger 2 ปีที่แล้ว +4

    Great video. It was direct to the point with all the info needed none of the info we didn't want!

  • @leftinashes
    @leftinashes 3 ปีที่แล้ว +3

    Good stuff man... Direct and to the point. Unlike those terrible random jokes! :) Also, what extension is displaying the the size of your imports?

  • @fhkodama
    @fhkodama 2 ปีที่แล้ว +1

    Pedro, great job. I started to follow you some days ago and I am really enjoying your content! Congrats.

  • @yeer32
    @yeer32 3 ปีที่แล้ว +2

    Finally a tutorial I could follow and not have to slow down playback speed. Do you have any flask + react authorization tutorials? Thanks a bunch!

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Thank you! Happy to hear you liked it! I am not that experienced with flask unfortunately!

    • @yeer32
      @yeer32 3 ปีที่แล้ว

      @@PedroTechnologies Unfortunate :( . Maybe its time to look into learning express or something, ill try and find some resources on your channel.

  • @unknownman1
    @unknownman1 3 ปีที่แล้ว +1

    Thanks man, this cleared my concept. I'm now gonna watch all your videos

  • @ibesarah3263
    @ibesarah3263 ปีที่แล้ว +1

    Thank you so much for this video. A great help for beginners.

  • @CurtisxLarsen
    @CurtisxLarsen 3 ปีที่แล้ว +12

    European --> It sounds a bit like - You are peein' -
    2 squared = 4 ---> "Too square" is slang for lame/uncool
    Pretty terrible jokes but thanks for the video

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Hahahaha I spent hours looking at the jokes from this API and i got like 30% of them

  • @AnujJoshi7
    @AnujJoshi7 3 ปีที่แล้ว +2

    How can We display the data without having to press the button? I tried by
    {name}
    But its not showing anything. I just wanted to remove the button input to display the data and show the data as soon as page loads

  • @randerins
    @randerins 2 ปีที่แล้ว

    I was just trying to translate an Axios request into fetch, now I know how. Thanks again, Pedro!

  • @justinekenyansa
    @justinekenyansa 2 ปีที่แล้ว

    the best explanation i've found online so far

  • @kochgamers
    @kochgamers 3 ปีที่แล้ว +2

    esse sotaque e nome nao me enganam, awesome video dude

  • @CourageousCreatives
    @CourageousCreatives 3 ปีที่แล้ว +1

    Great and clear explanation with a few terrible jokes (which are totally my jam)! Thank you!

  • @romulosendoromulo
    @romulosendoromulo 3 ปีที่แล้ว +1

    I think I might be becoming a fan. Thanks for the explanation

  • @jimshrestha3421
    @jimshrestha3421 2 ปีที่แล้ว

    thankyou, this tutorial was very helpful. the jokes were hilarious btw.

  • @satyadheemanth9628
    @satyadheemanth9628 3 ปีที่แล้ว +1

    Crisp and clear...Too good...Thank u

  • @buhutimanakal
    @buhutimanakal 3 ปีที่แล้ว

    Love the way you simply explain it. Greetings from Sri Lanka

  • @0Ipsita0
    @0Ipsita0 2 ปีที่แล้ว +1

    It was really an amazing video. 🤩 It is having all points to get clear Ideas about axios and fetch. 😊

  • @irtizamahmud6239
    @irtizamahmud6239 3 ปีที่แล้ว +1

    you are very good teacher. Short video with clear explanation. keep it up.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      Thank you so much! I really apreciate the support!

    • @irtizamahmud6239
      @irtizamahmud6239 3 ปีที่แล้ว

      @@PedroTechnologies you are welcome

  • @howabadworld
    @howabadworld 2 ปีที่แล้ว

    That's exactly what I'm looking for.
    Thank you and keep going!

  • @madhurjyagogoi5353
    @madhurjyagogoi5353 3 ปีที่แล้ว

    after seeing this video my all confusion is clear. Thanks, man!

  • @_boza
    @_boza 2 ปีที่แล้ว

    I like your tutorials. It really helps. Keep up the god work.

  • @simranbanwait
    @simranbanwait 2 ปีที่แล้ว

    Thanks bro , hey make sure to zoom in when you’re writing code , it was very tiny

  • @waynesrants
    @waynesrants ปีที่แล้ว +1

    I have not seen someone explaining the first joke so : If you're in the toilet, you are peeing (European)

  • @lionelemanuelson
    @lionelemanuelson 4 ปีที่แล้ว +2

    Thank a million!! I like your video's. Could you make a vid showing how to setup a baseURL with a JWT header? those videos are hard to find

    • @PedroTechnologies
      @PedroTechnologies  4 ปีที่แล้ว +1

      Yeah, I've been putting off making my third video of a small series I have on my channel teaching about authentication. The third video teaching JWT is coming probably this week!

  • @boubaker86
    @boubaker86 11 หลายเดือนก่อน

    The reaction to the jokes was hilarious 🤣🤣🤣🤣🤣

  • @Bemoregetmore
    @Bemoregetmore 2 ปีที่แล้ว

    This video really come through, thank you!

  • @electroviper5931
    @electroviper5931 2 ปีที่แล้ว +4

    Note : If you want to learn Axios don't skip this video.

  • @ThColinPereira
    @ThColinPereira 3 ปีที่แล้ว

    This video helped me so much! Thanks pedro

  • @valoriebroderick
    @valoriebroderick ปีที่แล้ว

    THANK YOU! FOR THIS AMAZING STRAIGHT TO THE POINT TUTORIAL!!!!!

  • @blottolotto7648
    @blottolotto7648 2 ปีที่แล้ว

    if u have little kids around those jokes would kill lol. great tutorial btw. I been using fetch but seems axios is a bit quicker.

  • @DaurenKurkenov
    @DaurenKurkenov 3 ปีที่แล้ว

    Thx for video!=))) Where is the list of open api which you have mentioned in video?

  • @shinchan4060
    @shinchan4060 3 ปีที่แล้ว +1

    Awesome no confusion now

  • @musicrecording1463
    @musicrecording1463 3 ปีที่แล้ว

    Thank you so much! Because of this video I accomplished what I needed to.

  • @simonezhang100
    @simonezhang100 3 ปีที่แล้ว +1

    Hi i have a question, id i had a multiple jokes what should i do? store them in an Array??
    Thanks!!!!

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      Yes! If the api returns a list you can set a state as an empty list!

  • @PROTECHRAHUL
    @PROTECHRAHUL 2 ปีที่แล้ว

    Hey sir. Can not we use axios or fetch directly in a component or can i make react component async

  • @codedByAyush
    @codedByAyush 2 ปีที่แล้ว

    This tutorial is super helpful!

  • @sunnyyoun8320
    @sunnyyoun8320 2 ปีที่แล้ว

    Thank you so much!! You helped me a lot

  • @fernandomartin9190
    @fernandomartin9190 3 ปีที่แล้ว

    Thanks for the vid, pretty clear. Btw, the API is down? I'm getting a 500 error. I can user another API though, but I wanted to get some jokes while I code. :(

  • @iSonikYT
    @iSonikYT 3 ปีที่แล้ว +2

    Great tutorial, but maybe you could have the browser and vsCode open side by side, instead of jumping between both programms.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      Thank you! I currently don't have 2 monitors, but im saving to buy another one! When I do I will keep vscode on one and the browser on another.

  • @SahilPatel-kh2rt
    @SahilPatel-kh2rt 3 ปีที่แล้ว +2

    Hey I am curious to know your vs code theme please tell me the name of it

  • @rosevermillion5055
    @rosevermillion5055 3 ปีที่แล้ว

    Is it possible to call getJoke without using a button? So when the page loads, the values are automatically shown in a label/textfield.

  • @bharatjagoar6092
    @bharatjagoar6092 2 ปีที่แล้ว

    worth liking bro !

  • @criaturaimaginaria5230
    @criaturaimaginaria5230 3 ปีที่แล้ว +1

    Nice video. I know how to use fetch and I find it easier than axios haha. I still do not understand why I should use axios instead of fetch and all te advantages that I can get using Axios.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      Both do the same hahaha I think axios is easier to understand for beginners and it has a great support for changing methods/opts

  • @NeoStreamLive
    @NeoStreamLive 3 ปีที่แล้ว +1

    I'm using react + node express, when I am sending post request using axios api request, it sends request to locahost:3000,
    the localhost:3000 is my react server, and my node server is localhost:4000. I had set the "proxy":"locahost:3000"(in client/package.json) but it has no effect. pls help my.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Hey if your node server is on the localhost:4000 then you should make the request to the localhost:4000!

    • @NeoStreamLive
      @NeoStreamLive 3 ปีที่แล้ว

      @@PedroTechnologies it is not working, I tried

  • @ibesarah3263
    @ibesarah3263 ปีที่แล้ว

    Please, how do we make a "post" request? Any link on that? Thank you.

  • @almoghasson5045
    @almoghasson5045 2 ปีที่แล้ว

    the european punch is read like "you're peein' "
    youre welcome

  • @simle11
    @simle11 3 ปีที่แล้ว +1

    can u pls make a vid how to use Axios and react on Node.js backed instead of other pre-made api's. make a small api and use it pls

  • @satyaganesh672
    @satyaganesh672 2 ปีที่แล้ว

    On point again. ThankQ Bro

  • @ricardocnn
    @ricardocnn 3 ปีที่แล้ว +1

    Hi! What's this extension that display the size of the packages?

  • @abderraoufrahmani8730
    @abderraoufrahmani8730 2 ปีที่แล้ว

    This is awesome, thank you :)

  • @Tyler-zb6ec
    @Tyler-zb6ec 2 ปีที่แล้ว

    Thank you!! great tut

  • @praffsphr1136
    @praffsphr1136 2 ปีที่แล้ว

    EXTREMELY USEFUL video, thank you KINDLY friend

  • @simranshaikh1665
    @simranshaikh1665 2 ปีที่แล้ว

    your videos are amazing

  • @TheNamesJT
    @TheNamesJT 3 ปีที่แล้ว +1

    How do you load the data on load no event? just when the page loads it displays the joke without a button?

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว +1

      You can use the useEffect hook for this, I have videos on useEffect if you are interested!

    • @TheNamesJT
      @TheNamesJT 3 ปีที่แล้ว

      @@PedroTechnologies I managed to figure it out I used useState and then just assigned the current state to the jsx html or w.e but when you reload the page the data doesn't get added instantly wound how you would get around that. Also, will check out your video on useEffect thanks for letting me know

  • @thevinylfortress
    @thevinylfortress 3 ปีที่แล้ว

    Thx dude, I owe you one!

  • @javierrivera6538
    @javierrivera6538 2 ปีที่แล้ว

    There is axios.post and axios.get I am assuming fetch is axios.get. What would be axios.post? Post is sending a payload data to the API to be validated.

  • @ahammedsha6135
    @ahammedsha6135 ปีที่แล้ว

    bro i want a help with you to make travel guide application with axios

  • @junnaid08
    @junnaid08 3 ปีที่แล้ว +1

    Great video. I am confused with setup?

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Thank you! What about the setup?

    • @junnaid08
      @junnaid08 3 ปีที่แล้ว

      @@PedroTechnologies response.data.setup. confused with setup word. where its come from

    • @TheestSuperlative
      @TheestSuperlative 2 ปีที่แล้ว

      @@junnaid08 It's nothing technical actually. It refers to the joke setup. In this data the joke is divided into to parts in the object (setup and punchline) { setup: "Can February March?", punchline: "No, but Aprill May" } so you can present it better in the app or show the punchline after the click etc.

  • @thisismyname723
    @thisismyname723 2 ปีที่แล้ว

    please ask your content consumers like me to drop a like after we consume your content. It helps with me considering you seriously

  • @czarscrib3680
    @czarscrib3680 ปีที่แล้ว

    Amazing 🙌

  • @ahnafadilsami312
    @ahnafadilsami312 3 ปีที่แล้ว +1

    can we do post and other request using fetch ??

  • @ChobacarsPortHarcourt
    @ChobacarsPortHarcourt 6 วันที่ผ่านมา

    God bless you so much you will make heaven

  • @JainamSutaria777
    @JainamSutaria777 2 ปีที่แล้ว

    Thanks PEDRO

  • @kazz97
    @kazz97 3 ปีที่แล้ว

    This guy is good. He's speedy and efficient! Love it.

  • @kathryncostantin8352
    @kathryncostantin8352 2 ปีที่แล้ว

    very helpful!

  • @you3667
    @you3667 3 ปีที่แล้ว +1

    thx. in nextjs or mern and so on, i use only axios ^^

  • @jeffreyhorton5934
    @jeffreyhorton5934 2 ปีที่แล้ว

    Dont know if you had gotten it yet, but the 2 Square joke is math lol ... " why didnt the 4 get into the club"

  • @masoomabbas5047
    @masoomabbas5047 2 ปีที่แล้ว +1

    the api link is not working

  • @mohitashliya8750
    @mohitashliya8750 3 ปีที่แล้ว

    good explained bro

  • @Aimless_Darinda
    @Aimless_Darinda 3 ปีที่แล้ว

    Best explanation

  • @girish2555
    @girish2555 3 ปีที่แล้ว +1

    To the point 👍

  • @dyhia9075
    @dyhia9075 2 ปีที่แล้ว

    thank you ! ❤

  • @devprakash5320
    @devprakash5320 3 ปีที่แล้ว

    nice explanation

  • @messyice2524
    @messyice2524 2 ปีที่แล้ว

    the punch line is that "you are peeing"

  • @khandoor7228
    @khandoor7228 4 ปีที่แล้ว

    Nice job Thanks!

  • @aminKedir
    @aminKedir 3 ปีที่แล้ว +1

    joke punchline explained. "European" as in "you're peeing" or shorthand "you're Peein" get it? lol but any who the video was amazing. thank you!!!

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Hahaha i'm dumb, I don't know why i didn't understand it!

  • @Maindev1994
    @Maindev1994 2 ปีที่แล้ว

    great video

  • @The-cyber-imbiber
    @The-cyber-imbiber 3 ปีที่แล้ว +3

    I think I might have taken the "punch line" a bit too literally. Now, I need to buy a new monitor. /:

  • @Ferreiragangofc
    @Ferreiragangofc 3 ปีที่แล้ว +1

    KING

  • @ID_Station
    @ID_Station 2 ปีที่แล้ว

    Bruh, I really loved this video but I can't believe you didn't laugh at this jokes lol! European? lol

  • @rlly6739
    @rlly6739 2 ปีที่แล้ว

    Thx so much

  • @wale66656
    @wale66656 2 ปีที่แล้ว

    Thank you

  • @pjguitar15
    @pjguitar15 3 ปีที่แล้ว +1

    I love you bro

  • @Y_hass
    @Y_hass 3 ปีที่แล้ว +1

    Just to explain the second joke, the word European is pronounced as "You are peeing" while in the bathroom.

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Thank youy hahaha Its actually pretty dumb of my part that I didn't understand lmao

  • @GiorgiBekurashvili
    @GiorgiBekurashvili 2 ปีที่แล้ว

    ❤️❤️❤️

  • @Saaaaaaaaaaaaaaaaaaadwadawdwad
    @Saaaaaaaaaaaaaaaaaaadwadawdwad 2 ปีที่แล้ว

    unfortunately that api is not working anymore..

  • @isloom-vb7nk
    @isloom-vb7nk 2 ปีที่แล้ว

    Api Link not working. Please repair it, bro

  • @harishg9429
    @harishg9429 2 ปีที่แล้ว

    The joke at the 1:45, read European as "eu r pean" or "you are peein(g)".

  • @umoooo
    @umoooo 2 ปีที่แล้ว

    i cant sleep, thinking about the joke all the time.. its so confusing what is it all about

  • @simranshaikh1665
    @simranshaikh1665 2 ปีที่แล้ว

    i didnt get any response

  • @ryanpmcguire
    @ryanpmcguire ปีที่แล้ว

    European = you’re-peein = you’re peeing

  • @digiartpassion8513
    @digiartpassion8513 2 ปีที่แล้ว

    API link not working anymore...link is a joke now !

  • @mj4232
    @mj4232 3 ปีที่แล้ว +1

    Hazlos en Español no seas mamón, te llamas pedro man seguro eres mexicano we, apoya al programador latino xd

    • @PedroTechnologies
      @PedroTechnologies  3 ปีที่แล้ว

      Soy brasileño jajaja Yo hablo un poco de español.