2.3 HTTP Post Request with fetch() - Working with Data and APIs in JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024
  • 💻github.com/Cod...
    We are now in Module #2! In the previous module, we focused on client-side JavaScript. We now will learn the basics of server-side programming with Node.
    2.3 Let's take data from the client and send it to the server. This video covers routing, JSON parsing, and HTTP POST requests with fetch().
    🎥 NEXT LESSON: • 2.4 Saving to a Databa...
    🎥 PREVIOUS LESSON: • 2.2 Geolocation Web AP...
    🎥 FULL COURSE: • Working with Data and ...
    🚂 Website: thecodingtrain....
    💖 Patreon: / codingtrain
    🛒 Store: www.designbyhu...
    📚 Books: www.amazon.com...
    🎥 Coding Challenges: • Coding Challenges
    🎥 Intro to Programming: • Start learning here!
    🔗 p5.js: p5js.org
    🔗 Processing: processing.org
    📄 Code of Conduct: github.com/Cod...

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

  • @matthewburson2908
    @matthewburson2908 5 ปีที่แล้ว +152

    My day is always better when I see new Coding Train videos.

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

    You can not imagine how long i searched for such a tutorial. Thank you. Just Thank you.

  • @user-qq7ch
    @user-qq7ch 4 ปีที่แล้ว +60

    This guy seriously makes the best tutorial content on TH-cam. I've learned SO much, all thanks to this guy. His videos are legit worth $1000s in semesters at my university. And no pressure of being graded!

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

    I've seen several instructional videos from you and I'm still impressed by the clarity of this despite the fact that you're very quick, but clear about what it's all about.
    Sometimes it looks like an Attention Deficit Hyperactivity Disorder (ADHD), but this is a natural gift in your case.
    Thank you very much and go on with it.

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

    This was the most comprehensive nuts-and-bolts explanation of fetch API I could find. Most other videos don't even come close. Thank you.

  • @user-qq7ch
    @user-qq7ch 4 ปีที่แล้ว +8

    Learning back-end coding at the moment. These videos are seriously awesome. Well-taught, good production, and helps so so much.

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

    oh just great. I tried learning this and googled questions and tried it out for an hour. And then when I finished I saw this video.
    THanks youtube.

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

    I've struggled with this for weeks. And finally, I found The Coding Train videos and they made it all so simple. Thank you man!

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

    Can I just say. I first started coding about 4 years ago as a hobby, these videos were always a constant source of joy and fun for me back then. I'm now a full-stack dev at a blockchain based startup, 4 years later I still love your videos. THANK YOU!! :)

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

    Great clarity for a person who really struggles to comprehend concepts delivered by stackoverflow people, you put it visually, legibly and repeatedly so the audience can review, re-review at their own pace. Thank you for helping everyone.

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

    I have no words, stumbled upon this and learnt quite possibly the most important way of client server interactions I have been trying to learn for months.

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

    I love the way u teach and the happiness u display, makes me remember when I was still a kid, thanks for that enthusiasm, smiles

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

    I have watched this video so much for when I need help on fetch's! You are an invaluable human, thank you for your brilliant work!

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

    I have been struggling with this server side stuff for DAYS, i go to coding train and 20 minutes later i know all i needed and been trying to learn for so long. You sir, are incredible

  • @rinovethamoses124
    @rinovethamoses124 5 ปีที่แล้ว +9

    Your videos are so useful for me.
    I have learned a lot about javascript through your videos.
    Thank you

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

    The way you explain things makes me fall in love with coding. thank you so much.

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

    Realllly man... Tonsss of thanks❤️❤️❤️❤️❤️🙇🙇.. after browsing through the internet, after going through several post cannot figure out this simple feature, that u explain in this short video.. i am really glad 😊

  • @hananfadah
    @hananfadah 7 หลายเดือนก่อน

    This guy is the best teacher heaven has sent for developers 😊

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

    Thank you, Daniel! Your energy and charisma are priceless. Getting mood and knowledge :)

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

    Coding Train guy, I really appreciate your hard work. I know these videos take a lot of work to produce and you are the best for putting these out here. Also, you should say your name more, so we can buy your book!!!

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

    This is the tutorial I have been looking for. Thanks a lot! Love everything about the tutorial. Including the new haircut!

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

    so easy to understand. after so many hours of finding my mistake and failing you saved the day. thx sir

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

    Man, I'm getting crazy just to understand what headers are, but this video made many things clearer to me than I expected!

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

    You are heaven sent, thank you! best node.js teacher on TH-cam by far

  • @ABDULMANAN-el8gr
    @ABDULMANAN-el8gr 4 ปีที่แล้ว

    Unfortunate this Video has only ~80k views. The Best Explanation ever.. I kind of love coding now because of you . Thank You so much

  • @Blue-bb9ro
    @Blue-bb9ro 2 ปีที่แล้ว

    Just found out this channel, I could tell you're a GREAT teacher, thank you for this simple explanation!!!!!

  • @roflox420
    @roflox420 5 ปีที่แล้ว +2

    This series is super. I have been working on a project that is using these things but I didn't know how some parts of this project work. Awesome! :)

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

    This video is simply amazing!!! I finally understood how the server and the client communicate each other, which I couldn't understand for more than a month in the course where I paid 800 euro!

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

    your classes are so much fun! congrats on being so didactic

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

      not sure if you truly mean 'didactic'?

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

    Wow I did not know how much I needed this! You actually make learning fun! Thank you so much :) My classes are very dry and boring in comparison.

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

    after days of post tutorials finally i understood .thanks bro

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

    Off the bat, I love your teaching style. Very clear.

  • @yt.mhasan
    @yt.mhasan 5 ปีที่แล้ว +1

    Every time I watch your video, I feel lucky for whatever reason!!!

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

    Dear you are great Teacher and your teaching style best for any student who just come to your channel.👏

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

    I cannot thank you enough for this, it has helped me with my personal projects so much.

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

    Spent two hours trying to figure out why req.body was returning undefined before coming across this tutorial... Thanks for making it

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

    Great video every time i re-watch I pick a little more

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

    Honnetly i dont speak english very weel and it the same to leastening somebody speaking quicly in english, but your video make me understand how node and api communicate. So thank u so much

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

    just what I was looking for, thank you for this video!

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

    Very nice video, I searched a long time for a video like this. Thanks!

  • @agled
    @agled 5 ปีที่แล้ว +13

    Man, you are awesome. I'm from Brazil and I always excited when youtube sugest to watch one of your videos. I have learning a lot! Thanks
    By the way, nice haircut. ;)

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

    Love the bell at the beginnings :D
    Great stuff as always!!

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

    EXACTLY what i needed. Firefox didnt like how i passed the information through i guess. Works now thanks to you!

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

    It's a beautiful day in the neighborhood, a beautiful day in the neighborhood, won't you be, my neighbor... sorry, love your tutorials but you reminded me of a childhood memory within the first 1 second of this video... LOL! had to comment (Mr Rogers if anyone remembers [Canadian TV show]). lol

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

    I had trouble with the POST fetch request when using live server.
    If you are having the same problem open "localhost:3000" in the browser instead of using the tab that live server uses.

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

      THANKS!!!!!!!!!! It was making me insane - what a trooper!

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

    I had some udemy courses on node but your videos have a different taste 🙂 I am glad you exist 😄 thanks for everything

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

    The way u introduce node was so helpful for me thanks alot man

  • @SteampunkSammy
    @SteampunkSammy 5 ปีที่แล้ว +36

    'API' instead of 'Rainbow'? my my.. that haircut has made you too sensible!!
    :) Great video as always

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

    Really appreciate your approach and enthusiasm! Makes understanding this stuff easier, for sure. Great content and explanations. Thank you!!!

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

    Awesome tutorial, best teacher ... ever ...thanks a lot !!

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

    I owe you a coffee for the help. This POST/GET things is killing me in my learning adventure!

  • @mitri-dvp
    @mitri-dvp 4 ปีที่แล้ว

    man, those headers always get me. Thanks for the video!

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

    Thank you for USE this type of teaching technic. Love From INDIA

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

    Quick question. I did every video step by step up to this point and i always get this error:
    POST 127.0.0.1:5500/api 405 (Method Not Allowed)
    Can someone help me about this? I am trying for a month now and I am hetting nowhere.
    I've downloaded your code as well and the error is still there. Please help!

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

      I had the same problem and so I made a directory(folder) called "api" inside the same directory as index.js. It seems to have solved it.

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

      Ok, I found the solution for the ERR_ABORTED 405 (Method Not Allowed)
      The error appears in the console of our index.html file when accessing the file DIRECTLY (in my case via VS Code - Live Server). By accessing directly to the file we somehow bypass the server logic or functionality.
      In order for the correct Server-Client functionality work we must enter the server via the URL "localhost:(whichever port its listening)" and as a result, the server will display the index.html and all the fetch functionalities should work. Cheers!

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

    I am a student from Uganda learning react Native. But I was looking for away to deal with API and now I have learnt thanks to "What does it mean to be a bubble?". Thanks

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

    Uhuu, after 4 days of lazy work i finally finished the exercises that he proposed in the video :D Ty Daniel

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

    I still didn't see the video. But that background already transmits me good vibes haha. Thank you!.

  • @PeterParker-mp7ns
    @PeterParker-mp7ns ปีที่แล้ว

    This is guy is so damn energetic. Makes things fun

  • @Ab-cj6gl
    @Ab-cj6gl 3 ปีที่แล้ว

    this channel and the net ninja channel are just crazy filled with information 😍

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

    Im searching for this from the past 3 hrs. Thank u so much

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

    You make everything so understandable!

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

    !!!!Important: I did all kinds of things and could never get body-parser or the new express.json() to work... And I finally figured out the problem was caused on Postman's side !
    I was sending a RAW payload and it was being sent as Text instead of JSON ! I changed that to JSON and everything worked 😊
    Hope this helps 😄

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

    That really made my day cleared all my queries.. Thanks Love from India

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

    GOoooD, you saved me lol.
    Hello from Mozambique here! :D

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

    Your video helped me a lot in my college project works. Thanks a lot😉

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

    My day always better when I code

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

    Thank you so much, this is what I was looking for and of course you had a video on it.

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

    I'm so so so grateful for this channel!!!

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

    They are great videos, I have learned a lot. I followed your instructions step by step but I couldn't save it to a database. spent the whole day again and again but no luck !

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

    Thank you. you saved my life.

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

    Followed the video step by step but im getting a 405 error saying method not allowed for my fetch api, any fix for this?

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

      The same. Have you found a solution?

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

      @@Devilman91 Ok, I found the solution for the ERR_ABORTED 405 (Method Not Allowed)
      The error appears in the console of our index.html file when accessing the file DIRECTLY (in my case via VS Code - Live Server). By accessing directly to the file we somehow bypass the server logic or functionality.
      In order for the correct Server-Client functionality work we must enter the server via the URL "localhost:(whichever port its listening)" and as a result, the server will display the index.html and all the fetch functionalities should work. Cheers!

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

    damn! i missed the express.json() in app.js and struggling all day why I get undefined in console .. u saved me now dude! Thanks a lot

  • @leamucho
    @leamucho 9 หลายเดือนก่อน

    great hair cut Dan, loved it! nice to see your quotidian jokes always!!

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

    finally i found this after thank u so much I was very confused how fetch works

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

    Great tutorial and explaination! Thanks! That space indentation makes me uncomfortable though.

  • @fede-tk3rm
    @fede-tk3rm 3 ปีที่แล้ว

    This video saved my life. Thank you so much :')

  • @hellmorgan8924
    @hellmorgan8924 4 หลายเดือนก่อน

    You are GOATED man, Thanks

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

    thank you very much you fixed my problem

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

    very good tutorial and just subscribed. Looking forward to your machine learning courses :)

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

    thanks a lot sir

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

    You’re amazing at teaching 👏👏👏

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

    Your tutorials are great and so fun :)

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

    Jeez Louise, and I thought XMLHttpRequest was confusing!
    This one's going to take some digesting.

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

    That was insanely helpful...

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

    It is always a pleasure to watch your video. I appreciate the fun energy and vibe you bring to teaching. You should look into paid teaching platform like udacity and udemy.

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

    Coding Train is great, but I keep wondering why Dan never runs into any CORS problems. Half of the fetch() calls I am making result in "Cross-Origin Request Blocked" errors. Extremely frustrating, as the documentation about CORS I have found so far is written in languages I don't understand, probably Sumerian or Etruscan.

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

      In all of my examples here I am making the request to the server hosting the code, so there are no CORS errors. I should DEFINITELY address how this works more in future videos!

    • @BerndBausch
      @BerndBausch 5 ปีที่แล้ว

      @@TheCodingTrain Thanks Daniel. I think I have figured it out by now, like a grown-up, but it is indeed confusing for a newbie. Especially when I get a same-origin error when innocently fetching something from the local filesystem (video 1.1).

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

    amazing video man, its exactly what i was looking for 👍❤️

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

    Awesome haircut, awesome video! :)

  • @eejazishaq4332
    @eejazishaq4332 5 ปีที่แล้ว

    Your the best code sir 👌 ever..
    Waiting for next episode of node.
    Thanks.

  • @adnanis-haq7462
    @adnanis-haq7462 3 ปีที่แล้ว

    where have you been all day of my life????????????.. .I've been looking for contents like this all my life, this on at 7:00

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

    When i wrote fetch('/api', options); in my index.html file and refreshed the page, it said 405 Method Not Allowed. Is there something wrong in the server side that does not allow the method POST?

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

      same thing here. Did you find what was wrong in your case?

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

      Add another header in the object that you are posting using fetch...
      mode: no-cors. This should solve it

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

      @@rijuban4321 it didn't work for me, but thanks for trying

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

      Ok, I found the solution for the ERR_ABORTED 405 (Method Not Allowed)
      The error appears in the console of our index.html file when accessing the file DIRECTLY (in my case via VS Code - Live Server). By accessing directly to the file we somehow bypass the server logic or functionality.
      In order for the correct Server-Client functionality work we must enter the server via the URL "localhost:(whichever port its listening)" and as a result, the server will display the index.html and all the fetch functionalities should work. Cheers!

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

      @@sebastiaanvv Ok, I found the solution for the ERR_ABORTED 405 (Method Not Allowed)
      The error appears in the console of our index.html file when accessing the file DIRECTLY (in my case via VS Code - Live Server). By accessing directly to the file we somehow bypass the server logic or functionality.
      In order for the correct Server-Client functionality work we must enter the server via the URL "localhost:(whichever port its listening)" and as a result, the server will display the index.html and all the fetch functionalities should work. Cheers!

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

    This guy is amazing!! Great video!!

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

    Thanks for this, u did this as I requested.

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

    Thankyou so much it is very helpful🎉

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

    love you man, I have learned a lot from your videos.

  • @andrewmasters6005
    @andrewmasters6005 5 ปีที่แล้ว +5

    I'm having a small issue. I can't get the data to transfer to the next page and I don't know how to fix it. My body is just constantly empty.

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

      Mine too, have you found what causing the problem?
      Also 'app.post' is flaged as "unresolved" in my Webstorm, I'm not sure why.

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

      Yeah same here... if anyone of you solved this problem, then please send the solution

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

      I had the same issue. It was a problem with my header.

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

      @@tdsimpson Me too, I write 'header' instead of 'headerS'

  • @SyntaxErrorz1
    @SyntaxErrorz1 5 ปีที่แล้ว

    This helped so much! Thank you! Love your videos!!

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

    you are a saviour...Thank you very much

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

    Thank you so much, professor 🥰

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

    Hey, I've got a quick question.
    When we first console.log'd the request, we got all of the data and it worked well, but when we specified request.body it didn't work anymore?
    You said that we needed to add the ability to parse any incoming data. How come the server was able to parse everything, but needs extra syntax when we want something more specific?
    Thank you for the great videos, these are really helping me out. I love your personality.

    • @SandFoxling
      @SandFoxling 5 ปีที่แล้ว

      I was wondering the exact same thing... considering all that data was also in json format

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

      Server did not parse the initial request data it just printed out whatever it received which was already in json format from client side but when we said request.body server had to parse it.