GET Data from API & Display in HTML with JavaScript Fetch API
HTML-код
- Опубликовано: 17 июл 2024
- 👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
Hi, I'm Wesley. I'm a brand ambassador for Kinde (paid sponsorship).
👉 Add auth to your app FAST: bit.ly/3QOe1Bh
👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
👉 Professional JavaScript Course: bytegrad.com/courses/professi...
👉 Professional CSS Course: bytegrad.com/courses/professi...
👉 Discord: all my courses have a private Discord where I actively participate
🔔 Email newsletter (BIG update soon): email.bytegrad.com
⏱️ Timestamps:
0:00 - Intro
0:44 - Get data with Fetch API (GET request)
3:07 - Display data by manipulating HTML / DOM with JavaScript
#fetchapi #fetch #fetchjavascript #javascript - Наука
This is the video that finally made API's "click" for me. So concise and informative. Thankyou!
jesus that may be the best tutorial ive ever seen about this. in only 5 minutes we got everything we need and also some extra really usefull knowledge. respect
I literally looked up entire YT, but couldn't find a single video that exactly teaches how to get and display data using API.
Luv u ♥
subbed after one minute. concise, clear, and well explained.
Hi, mastering JavaScript is critical if you want to be a modern, professional developer: www.udemy.com/course/professional-javascript-course/?referralCode=0C1D5752923168BC87C2
Also, if you are a front-end developer then mastering CSS (including Flexbox, CSS Grid, etc.) is equally important: www.udemy.com/course/professional-css/?referralCode=4C3C08E82629E6B15752
Excellent video. Straight to the point.
Kudos man.
Thank you so much! Finally I have the API result in a multiple select in the HTML form!
Thank you! I've been trying to figure this out for a couple of days now.
I never understood api's when they talked about them in college, now i have to work with them, so im doing some research and this 5 minute video made me understand them xD Thank bro keep it up!
yeah this explained the fundamentals so well, im glad i didn’t watch the 3 hour videos instead
Very awesome video. Conscise and straingt to the point. Thamk's for saving my life after almost a week of trying and searching
Great catalogue of videos rich with content! Thank you very much for the tips
Really a perfect explanation. Professional flow😊😊
This is a solid video. Thanks for the good work!
Thanks man. I was looking for this!
thank you for this video! was exactly what i was looking for
was looking for this! thank you
Thanks bro, very nice and informative video
Eye opening! Thank you very much
Very useful lesson. Thanks
Thank you very much for an informative video, helped to continue with a task
amazing api video ever thank you bro for this amazing video
Thank you very much 🫡
Thanks for the tutorial sir. I appreciate it
You saved my life at school today
awesome vid! Thanks so much!
YOU ARE A GOOD, MY KING, OMG This video solve my problem thanks my man
Thank you for this awesome video
Thank you
Thank you so much man
thank you nice explanation
Thank you.
hi, i'm looking for a way to store api data in a variable, so that i can reuse it later. i'm not sure if this is the right way people do.
Is there possibility to fetch data from ftp or local folder? Or on which sites can I automatically send files?
I think replacing forEach with map is better. Of course 'join("")' it afterwards and inject it in ul html element afterwards
that was what i was thinking too
i have always love to use map on arrays
Can I use a route in place of url . I want to fetch data from mongo db .
What if I want to store this data in a variable and then use it later
Please I have a question
When do you use fetch api
Hello :) thank you for your video, but there is a mistake, you should give a new variable and assign "Array.form(data), if you don't write this line, your code wont work. Thanks bro
Thanks!
Appreciate the Super Thanks! Thanks
Great video. I did have a problem with line 22. Had to change to "" +user.name+ "" to get it to work. Otherwise it just quoted the line. I guess this is a browser difference or something.--- Update. Okay so I was using the wrong key. I thought it was the single quote key instead of the back tick or whatever you call it. Me Bad!
That's why he used $ sign for back tick
Is it good to fetch data from api and save it in database for a page that we load several times or use api directly?
It’s a lot more work with database
Thanks a lot sir 🙏, is there any website reference to learn the ( ` ) symbol ? I'm inserting the wrong symbol ( ' ) when declare "markup" variable on 3:52 😄
it is backtick available in keyboard below escape button
backtick ``
@@kvkcreations2313 Thank you so much sir 🙏
Its template literal
gd one
nice video but there is one thing i dont understand.. suppose we used async await to get the data.. how can we then use the same data in lets say 10 other functions without having to fetch the same data over and over again in all the functinos
Sorry too busy to give you a complete / good answer. You would just assign the data to an outside variable. I highly recommend to go through my Professional JavaScript course so these things become easy.
You could cache the data. You can watch a tutorial on caching.
But for I get an error said: data.forEach is not a function.
Check if data is actually an array (console.log it)
@@ByteGrad Thank you dear but I got where the error cames from. Within my foreach loop : data.ArrayName.forEach
Is this not compatible on webflow ? because it is showing ${user.name} instead of actual user name for each user
Interesting use case, I don’t know how to do this in Webflow
@@ByteGrad Completely my mistake. Your solution works like charm. I used ' instead of `. Thanks a lot
Can we display a specific data using the id value??
You can fetch any data you like, yes
data already array, but when i add the "data.foreach...." is said is not a function
It’s forEach (with capital)
Why none on these fetch tutorials explain how they create their api? Please
bro I've been asking a question for a year, which made me confusing about my learning skills, or my brain IQ let me say, the question is : can I use the fetched data from the API outside the promise? this question is not just mine, there are many beginners have this questions, and had this question, if not all the leaners had asked this question yet, the main here is if u can do a video about that it will be really helpful, the answer with yes u can or not u can't will be helpful not just if there is a possibility, and thanks for reading this
Why not create a variable outside the scope of the fetch function and then when you receive the data just save it that variable. Since that variable is outside the fetch function, you can use it's data outside of the function.
can i use append instead of insertAdjacentHTML?
Better to use insertAdjacentHTML if you have a string representing HTML.
We want to insert a string that will be parsed as HTML so we have to use insertAdjacentHTML, if you use append the string will simply be text and if you use appendChild you have to create an HTML-element / 'node' to insert first.
@@ByteGrad ohhh okay understood, thanks ♥️
Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerHTML')
Its showing this error even I tried put the script tag below table tag but not working.
Seems like you didn’t select the HTML-element properly
@@ByteGrad
Actually I am doing it for table(showing Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerHTML'))- Can you help with this?
----------------------------------------------------------------
id
it
titile
body
async function fetchApi(){
let result = await fetch("jsonplaceholder.typicode.com/posts");
result = await result.json();
console.warn(result);
document.getElementById(data).innerHTML = result.map((data)=>(
`
${data.body}
${data.it}
${data.body}
${data.userId}
`
)).join();
}
fetchApi();
Can I get Any Data from Any Website from this Method??
tried doing this for the pokemon api in my bootcamp it doesnt work
Any error messages?
how would I fetch only the data of an object thats not an array?
subscribed by the way
You would get the data the exact same way, but just handle it differently once you get it.
data.forEach is not a function (console error)
Check if data is actually an array: console.log(data) and see what you get
index.htm:13 Uncaught (in promise) TypeError: data.forEach is not a function
Try console.log(data) to see if you actually have an array
thanks but next time provide a link to API
Ik hoor Nederlands
source code ?