Read an API's Docs

In the last exercise, you wrote the getHolidays() and saveWeekend() functions that the planner can trust with real servers. Every URL in them came from these lessons, though. When you build a program that uses another API, as you will at the end of the course, you’ll find the URL in the API’s documentation.

The planner needs that skill now. It still has only holidays and no country names, so before it can load all four friends, you’ll find both of its requests yourself in the APIs’ docs.

In this lesson, you’ll use two real API references to find each API’s base URL, endpoint, parameters, and expected responses, then build working requests. You’ll also see why docs need a date next to them. Start with the API you already know: Nager.Date.

Read Nager.Date’s Reference Together

You already know what Nager.Date answers, so its reference is a good place to learn what to look for in any other one.

Open https://date.nager.at/Api in your browser. It redirects you to nagerholidays.com, the project’s home, where the quick start shows GET /api/v4/Holidays/{CountryCode}/{Year}, the path your getHolidays() already calls.

Click API Documentation to open the full reference. It starts on Pro - API V1, a version that needs a key. The name at the top of the sidebar is a menu, so pick Community - API V4 there. Then find the endpoint titled Retrieve the list of all public holidays for the specified year and country.

An endpoint is one kind of request an API answers, made of a method and a path. Read its entry in the reference in this order:

  • The endpoint: GET /api/v4/Holidays/{countryCode}/{year}. The braces mark path parameters, placeholders you replace with your own values.
  • The parameters: countryCode is a required string, “A valid ISO 3166-1 alpha-2 country code”, which is a two-letter code such as PT. year is a required integer. This endpoint has no query parameters.
  • The base URL: The request example reads curl /api/v4/Holidays/us/2026, with no origin. Expand the IotHolidays group lower on the page. Its example calls https://date.nager.at/Api/v4/..., so the origin is https://date.nager.at, the one the planner already uses.
  • The responses: 200 with a list of holidays, 400 when “The request was invalid”, and 404 when “The provided country code is invalid or not recognized.”

The example response shows "name": "string" and today’s date. Those are placeholders that show the shape and the type of each field. Tick Show Schema to read what each field means. For example, nationalHoliday “Indicates if this holiday applies to the entire country,” and subdivisionCodes can be null or an array.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.