Asynchronous JavaScript Tutorial #9 - The Fetch API

Поделиться
HTML-код
  • Опубликовано: 31 янв 2025

Комментарии • 120

  • @ckatke
    @ckatke 4 года назад +88

    He is true ninja
    Killing every web dev technology
    With his sharp explanation skills

    • @fahimemroz9141
      @fahimemroz9141 4 года назад +14

      There are many great web educators here on youtube, but I think we can all agree that TNN is the best explainer amongst all of them.

    • @fahimemroz9141
      @fahimemroz9141 4 года назад

      @UCbyK7J6w9Pg97edZ2BdZdRg The Net Ninja, TNN is his channel's initials bro

    • @ckatke
      @ckatke 4 года назад

      @@fahimemroz9141 ohhh

    • @maskman4821
      @maskman4821 4 года назад +1

      @@fahimemroz9141 agree, master ninja rules and rocks !!!

  • @TinyMaths
    @TinyMaths Год назад +11

    Thanks to this series, coupled with API specific instructions on the web, I can go about making a weather app, largely on my own, incrporating it into time and date apps I've built. A week ago I had absolutely no idea how to go about getting and manipulating the data for such a project! I know, far too many weather apps have been built 🙂, but I'm just excited to be able to build one, just like the thousands of people who were able to do so before me.

  • @user-zb5jp4ti1d
    @user-zb5jp4ti1d 4 года назад +7

    wow... i was until now struggling with why two then blocks with a fetch API... this is a brilliant deconstruction. i think i finally get it now. Thanks so much Shaun for all that you do.

  • @tensetv
    @tensetv 3 года назад +15

    I had to choose between Netflix and your videos and obviously I'm here! Really nice content!

  • @hertechera
    @hertechera Год назад

    This is the simplest explanation I've seen so far that makes the most sense. Thank you so much

    • @NetNinja
      @NetNinja  Год назад

      Glad it was helpful! :)

  • @AndrewMycol
    @AndrewMycol 2 года назад +3

    I was looking for a introduction to the fetch API, since I've mainly used jQuery to do API calls, and this video did a very good job of it. Really easy to follow and understand.

  • @Harry-qz4iq
    @Harry-qz4iq 3 года назад

    You're underrated... I've not understood async JavaScript as much as I do now after watching your videos.

  • @keifer7813
    @keifer7813 2 года назад

    I love this guy. Anytime I can't figure out something, he has a video for it and it becomes a walk in the park. Absolute leg!

    • @NetNinja
      @NetNinja  2 года назад

      Aha, thanks Keifer :)

  • @ahmedtouzani6780
    @ahmedtouzani6780 4 года назад +10

    Thank you so much ninja for your courses , you are the best on this earth ;) keep going bro

  • @ignjat4123
    @ignjat4123 2 года назад +1

    Thank god The Net Ninja exists. I don't know what I would do without his great videos.

  • @m__link6499
    @m__link6499 3 года назад

    you are the best teacher I've ever seen. After struggling with fetch concept during months, now I get it...

  • @TonyGonzales
    @TonyGonzales 8 месяцев назад

    Oh, to like this entire playlist at once. Plenty of folks are ready to explain fetch, but few go into the rigmarole of explaining the guts of the thing (which is what my wandering mind needs.) I "promise" to check out your Udemy course. Best of luck.

  • @ahmed_music
    @ahmed_music 3 года назад +1

    Net ninja has pretty good explaining skills. Every topic is to the point and very clear. Thank you for these great videos!

  • @Mersal-uj5nh
    @Mersal-uj5nh 4 года назад +2

    Your the best frontend teacher I have seen so far 👌👌👌

  • @blazesmt
    @blazesmt 3 года назад +3

    I was stuck on learning api's and node.js for over a week and you helped me figure it out. God bless you

  • @Saiyan1987
    @Saiyan1987 Год назад

    By far the next explanation i have come across for the fetch method. Thanks!

  • @mladenkaorlic
    @mladenkaorlic Год назад

    This content is literally golden, even I understood it

    • @NetNinja
      @NetNinja  Год назад +1

      That's great to hear :) thanks

  • @fathyadel4892
    @fathyadel4892 4 года назад +2

    man u did it
    u the best instructor believe me

  • @ferrouswroughtnaut3230
    @ferrouswroughtnaut3230 Год назад

    Ninja, you are a wonderful instructor! I understand everything you taught!

    • @NetNinja
      @NetNinja  Год назад +1

      Happy to hear that! :) thanks for watching

  • @bigshuff
    @bigshuff 6 месяцев назад

    what a fantastic and easy to understand vid, Thanks so much. Taking a course with an internet training provider, wished they made so easy to understand. ha ha.

  • @spes9850401
    @spes9850401 Год назад

    This course is so well organized. It definitely deserves a Kudo

  • @subhajitdey135
    @subhajitdey135 2 года назад +1

    Man You are an amazing mentor 🙇‍♂️🙇‍♂️

    • @NetNinja
      @NetNinja  2 года назад

      Thanks Subhajit! :)

  • @blog.pymastery
    @blog.pymastery 4 года назад +1

    Great job.
    Now I know three ways to get APIs data so far.
    Thanks Net Ninja :)

  • @finonomastropiero4261
    @finonomastropiero4261 4 года назад

    if may i say Ninja, you should put a "hi-pass filter" on your voice record. Set it up for about 80hz, so all the bassy of your voice would get rid off. It can be easily done despite of any video editor you use. Thanks for this update of that godamn api !. mucho love

  • @shreyasnair02
    @shreyasnair02 Год назад

    Dude, you're a freaking legend

  • @wandysantana7151
    @wandysantana7151 4 года назад +1

    Wao amazing, right now I understand how it works everything behind scene!

  • @AlexanderYossifov
    @AlexanderYossifov 4 года назад +1

    Best of the best explanation. Respect!

  • @papaAmanfo
    @papaAmanfo 2 года назад

    Your are a great teacher..!

  • @cjmaaz
    @cjmaaz 4 года назад +2

    You should get a million views.

  • @steverogers5875
    @steverogers5875 4 года назад +2

    Greatly explained

  • @dweebycat9929
    @dweebycat9929 2 года назад

    Amazing, thank you so much, you're my main go-to guy when I need a better explanation!

  • @dansmar_2414
    @dansmar_2414 2 года назад +1

    this is gold. Thank you for sharing so great content

  • @sumiyasayeed2651
    @sumiyasayeed2651 2 года назад

    You are the very best 😍 please keep it up

  • @AhmadAli-wt8zy
    @AhmadAli-wt8zy 4 года назад +5

    you are amazing👍👍

    • @NetNinja
      @NetNinja  4 года назад +5

      Thank you so much 😀

  • @f19-x9k
    @f19-x9k 3 года назад

    you are so spot on with your words, sir. thank you very much!

  • @swoorp
    @swoorp 4 года назад +2

    Loved it!!!

  • @knotcircle2844
    @knotcircle2844 2 года назад

    Thanks for this clear explanation.

  • @nitinsoni9956
    @nitinsoni9956 4 года назад +1

    fetch('best tutor on youtube').then((res)=>{return res.json()}).then(data=>{console.log(data)}).catch(err=>{console.log(err)}) // output: [{Best Tutor: 'Net Ninja'}]

  • @skfahim6776
    @skfahim6776 3 года назад

    truely you are a ninja

  • @lulusaikou221
    @lulusaikou221 2 года назад

    Thank you very much! Really helpful!

  • @suatbayrak2703
    @suatbayrak2703 4 года назад +1

    hello thenetninja, will you make videos for mern stack ??

  • @karthiknani537
    @karthiknani537 4 года назад

    you are more than awesome my friend

  • @jupixel
    @jupixel 2 года назад

    Thank you for your explanation
    I have a question:
    Is it generally better to do the api fetching by writing in frontend or backend?

    • @NetNinja
      @NetNinja  2 года назад

      It really depends. If you're using sensitive data (such security credentials) in your fetch, then definitely backend, because you don't want those to be exposed from the frontend. There are other reasons too, but they would be very specific to the use case. Otherwise, you can allow the frontend to carry out some of the fetching work :).

  • @heysalah
    @heysalah 4 года назад

    Great video🤍 are there any mern stack playlist soon? I’m excited

  • @soumyaranjanpanda7532
    @soumyaranjanpanda7532 3 года назад

    perfect explanation !

  • @ai.aspirations
    @ai.aspirations 3 года назад

    Perfekt my friend!

  • @Martin958
    @Martin958 4 года назад +1

    Is it possible for you to combine a course using HTML and CSS to create a login, register and logout interface, using PHP to register the users for logging in and then combining it with Javascript to allow them to chat with each other using Asynchronous Javascript? Also adding sessions for guests with unique but temporary guest ID's on the MySQL database? I would consider paying for that too as a project course.

    • @TuringTested01
      @TuringTested01 3 года назад

      hahahah PHP hahahahah.....even reading those three letter together makes me cringe.

    • @joker_j1268
      @joker_j1268 3 года назад

      Yes it is possible

    • @Martin958
      @Martin958 3 года назад

      @@joker_j1268 I think it's not possible that he will do this as a project.

    • @Martin958
      @Martin958 3 года назад +1

      @@TuringTested01 What's so hilarious about PHP. He runs courses in that language, and it's still used widely.

  • @reyesdf
    @reyesdf 3 года назад

    my top tuts playlist when im lost or i forget something.

  • @ridl27
    @ridl27 4 года назад

    greetings Shaun :) just wondering, any chances to see in the near future some Next/Nest/Angular series ?

  • @Pensive_117
    @Pensive_117 Год назад

    Great video

  • @Ahmedhossam-jz5eg
    @Ahmedhossam-jz5eg 3 года назад +1

    How does the program know that the "data" is what our file hold "luigi"
    we didn't define the object data and store any information in it
    thanks

  • @asmereg
    @asmereg 4 года назад

    Please do an updated react course

  • @4541047
    @4541047 4 года назад +1

    Hi,
    What is the github repo for this series?

  • @redaalii
    @redaalii 4 года назад

    Thank you ninja

  • @hox7125
    @hox7125 4 года назад

    thanks ninja

  • @jinyuchan3983
    @jinyuchan3983 3 года назад

    Is there an example where you don't use console.log? What if I want to get the values and assign them to a variable to be used?

    • @davidtovmasyan691
      @davidtovmasyan691 2 года назад

      I've been struggling with that too, you must write an additional function which will assign your data to that variable.

  • @hongquannguyen5532
    @hongquannguyen5532 10 месяцев назад +1

    6:49 what the hell, its so simplified

  • @william.n4643
    @william.n4643 Год назад

    I like to ask something,
    response.json() is return a promise right? And .then() return a promise also right? In the video you return a response.json() inside .then(). So is it means it return a promise inside a promise?
    I hope you understand what I mean

  • @nizamuddinshaikh3185
    @nizamuddinshaikh3185 3 года назад

    What if no data is returned from server and a template is rendered to response, instead? Will the template be rendered in browser?

  • @hafidznugroho520
    @hafidznugroho520 4 года назад

    can we use JSON.parse(response) instead of response.json() while fetching data?

    • @sams1669
      @sams1669 4 года назад

      response.json() automatically parses the data , which can then be chained. Also you write less code.

  • @ayushthakur2896
    @ayushthakur2896 3 года назад

    @7.09 If we console log response.json inside the first then block instead of using the chaining promise will that be wrong

  • @fredpourlesintimes
    @fredpourlesintimes 3 года назад

    Not that easy to understand - especially the usage of return (apparently required for the chaining) -, but you offer a bunch of pretty useful example of the promise ecosystem.

  • @heavydirtysoul1491
    @heavydirtysoul1491 3 года назад

    it is still not clear how to handle errors if fetch returns resolve object anyways. and catch doesn't receive err.

    • @heavydirtysoul1491
      @heavydirtysoul1491 3 года назад

      i believe that in the first 'then' we should put something like this:
      .then(response => {
      if (response.status === 200) {
      return response.json();
      } else {
      throw new Error('Something went wrong');
      }
      })

  • @nick_jacob
    @nick_jacob 3 года назад

    Where is "err" coming from? Is that something built into javascript? Am I missing something?

  • @91bravic12
    @91bravic12 Год назад

    What would be the reason for this error: rejected SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
    I can't figure this out at all. I created my own JSON file and I get this. Also trying this in a REACT project.

  • @Steve-Richter
    @Steve-Richter 4 года назад

    Promises code is totally confusing to read when await is not used.

  • @WiBla
    @WiBla 4 года назад

    Why does the fetch API returns a promise when using response.json()?
    As we have seen from the XMLHttpRequest, parsing a string to JSON can be done synchronously, so why bother?

    • @koustubhmuktibodh4901
      @koustubhmuktibodh4901 4 года назад

      Response.json also returns promises. So we need to chain another function after that.

  • @tourdesource
    @tourdesource 3 года назад

    A slight correction: the fetch API is not part of the Javascript language. It's a browser API.

  • @meta7gear
    @meta7gear 4 года назад

    And now I understand why everyone uses Axios instead of the fetch API.

  • @AhmedKhan-rt6oz
    @AhmedKhan-rt6oz 2 года назад

    Awesome

  • @ridl27
    @ridl27 4 года назад

    ty.

  • @fahimemroz9141
    @fahimemroz9141 4 года назад +1

    Please use the bracket matching extension on vs code, makes it really easy on the eyes.
    Anyways, great video as always Mr Pelling. Thank you for educating us for free like this.
    I'm currently taking your Vue2 course here on youtube (it's great btw).
    Anyways seeing as how Vue is now the top front-end framework on Github (173k+ stars) and how Vue has been updated, Do you have any intentions of doing a Vue3 course here on youtube?
    Thanks

  • @suryapratapsinghnaruka3111
    @suryapratapsinghnaruka3111 2 года назад

    How can I get upper 10 objects from api using fetch api

  • @MrFxJ
    @MrFxJ 4 года назад

    How to display the data returned from reponse.json() in HTML ?

    • @shr1han
      @shr1han 4 года назад +1

      The .json() method would be rejected if the requested data is HTML(or really any other data type than JSON). Because the html Syntax would start with something like

    • @MrFxJ
      @MrFxJ 4 года назад

      @@shr1han What I meant is: How can I process the JSON returened from the function so I can display the JSON in HTML. Example: const data = response.json(); document.getElementById('h1-element').innerHTML = data[0].name;

    • @YuyinSports
      @YuyinSports 4 года назад

      @@MrFxJ after fetching the data you would have an array. Then you can loop thought it and create html tags for each using `backticks` to insert the values. Then adding them to a variable "output" or whatever to then have it injected with the innerHtml method. It would be something like:
      data ={title: 'node ninja tutorials are cool', snippet: 'I've learned a thing or two...'}
      data.forEach( (item) => {
      output = '' (empty variable)
      output += `
      ${blog.title}
      ${blog.snippet}
      `
      }
      document.querySelector('.card'). innerHtml = output

  • @oddjamic
    @oddjamic 4 года назад

    any Vue3 course ?

  • @prakashmahat9947
    @prakashmahat9947 3 года назад

    I wish I can could meet you in person. An Anonymous mentor!

  • @abderrahimtamda3990
    @abderrahimtamda3990 2 года назад

    100%😊

  • @Darkpill-2
    @Darkpill-2 Год назад

    The #1 mistake tutors make is teaching students an outdated long way of doing and then telling them there is a better way to do it. People can only absorb so much. Teach the easy way that works and students will learn other ways down the road.

    • @karthikraj9394
      @karthikraj9394 Год назад

      If you go to an interview they don't ask you the easy ways

    • @Darkpill-2
      @Darkpill-2 Год назад

      @@karthikraj9394 in interviews you can solve the problem or not.

  • @AhmedKhan-rt6oz
    @AhmedKhan-rt6oz 2 года назад

    watched 9/10

  • @joydeepbhattacharjee5305
    @joydeepbhattacharjee5305 4 года назад

    Waiting for episode 10

  • @yadude101
    @yadude101 3 года назад

    at :37 ...no i think he did it just to annoy us 😀

  • @prafulrane3591
    @prafulrane3591 2 года назад

    Anyone in 2023

  • @Pensive_117
    @Pensive_117 Год назад

    Stupid syntax.

  • @techaddictdude
    @techaddictdude 2 года назад

    I am a bit late, but I didn't understand the last part where you first said that data.json() contains the actual data but instead of assigning it to a variable or logging it to a console why you used another .then()?

  • @CHAMONIX552
    @CHAMONIX552 8 месяцев назад

    the fetch returns response.json().
    Does it become data in the following step?

    • @Alluriah
      @Alluriah 7 месяцев назад

      when we have return response.json() that one is an object or array depending on your case we then take that thing and since it's the only thing it returns we can name it whatever and use it forward, convention is that we name it data, you could name it books, blogpots whatever you want it will only reffer to that returned value.