DEV Community

Cover image for Eazy Way to, How to Fetch API using JavaScript..πŸŽ‡
Roshan Shambharkar
Roshan Shambharkar

Posted on • Updated on

Eazy Way to, How to Fetch API using JavaScript..πŸŽ‡

So How Do we Fetch API in JavaScript in, javaScript There is a inbuild method which is called fetch()The fetch() method in JavaScript is used to request to the server and load the information in the webpages. The request can be of any APIs that returns the data of the format JSONor XML. This method returns a promise,

Image description
So lets come up with the Approach,
Step 1. First make the necessary JavaScript file, HTML file and CSS file.
Step 2. Then store your API URL in a variable.
Step 3. Define a async function (here getapi()) and pass api_url in that function.
Step 4. Define a constant response and store the fetched data by await fetch() method
So lets get start

First We will Create HTML file And Js files
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<main id="app"></main>

JAVAScript File

`function getData() {
.then(res => {
return res.json();
.then(json => {
const html =
.map(function(item) {
return "

" + item.first_name + " " + item.last_name + "

document.querySelector("#app").insertAdjacentHTML("afterbegin", html);
.catch(error => {


You can find output of this Example in here

Top comments (0)