javascript

How to Use Fetch API in Javascript

In this tutorial, we are going to use the Fetch API to fetch all public holidays in the United States.

We’ve have written extensively on the Fetch API here.

So, let’s begin.

  getUsHolidays = async () => {
   const url = "https://date.nager.at/api/v2/publicholidays/2020/US";
    const obj = {
      method: "GET",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
    };
    await fetch(`${url}`, obj)
      .then((response) => response.json())
      .then((responseJson) => {
        console.warn(responseJson);

      })
      .catch((error) => {
      console.error(error.message);
      });
  }

Explanation:

Here, we’re using async/await with GET request method, and the content type is application/json.

We’re getting the response on the console and we’re also catching errors as well because, should the request not go through, we want to know what happened.

Result:

Fetch API in Javascript

Conclusion:

Here’s how we can make a simple GET request using Fetch API in Javascript. Let me know what you think in the comments.

check out the official documentaton here

Recent Posts

Check if Number, Word or Phrase is a Palindrome in JavaScript

What is a Palindrome? A palindrome is any word, phrase, number, or sequence that reads…

6 days ago

How Facial Recognition Software Works

Facial recognition technology is rapidly changing how we interact with devices, access services, and enhance…

1 week ago

Why Grok 4 is the AI Game-Changer You Need to Know

Move over ChatGPT, there's a new, significantly upgraded player causing a stir. xAI, Elon Musk's…

2 weeks ago

Cloudinary vs. AWS vs. ImageKit.io vs. Cloudflare

Choosing the right asset management service is vital. Cloudinary is frequently mentioned, but how does…

4 weeks ago

How to Integrate Cloudinary with PHP

Cloudinary is a powerful cloud-based media management platform that allows you to upload, store, manage,…

4 weeks ago

Trump Extends U.S. TikTok Sale Deadline to September 2025

In a surprising turn of events, former President Donald Trump announced on June 19, 2025,…

1 month ago