Amara in Lisbon, Jonas in Berlin, Keiko in Osaka, and Mateo in Mexico City want to find long weekends in 2026 when they can meet. Their planner first needs public holiday data for one country, starting with Portugal. A server on the internet has that data.
You might already know the usual recipe of fetching a URL, getting JSON, and using it. That recipe works until a request fails, and then it can’t tell you why. In this lesson, you’ll read the actual messages that travel between your computer and a holidays server. You’ll name each part of a request and a response, and you’ll see why the holidays arrive as text that your code still has to parse. Start by asking the server yourself.
Ask a Server for Portugal’s Holidays
The planner needs data that lives on someone else’s computer. A web API is a server that answers programs instead of people. You send it a precise question, and it sends back data your code can use. The holidays come from Nager.Date, a free public holidays API that needs no account or key.
Every question you send to a web API is an HTTP request, and every answer is an HTTP response. HTTP, short for Hypertext Transfer Protocol, is the set of rules both sides follow. This course is about what’s in those two messages, how to send them from JavaScript, and what to do when the answer isn’t the one you hoped for.
The course assumes that you can write async functions with await, run several of them together, and catch their errors. You also know JSON and ES modules, short for ECMAScript modules. You’ll get a one-line reminder of each concept when it comes up. If you’re arriving here directly, you can follow along as long as you’ve written code like that before.
In this course, you’ll call two real, free APIs a handful of times: one for holidays and one for country names. The lessons show output from dated runs. Coding exercises run in your browser against stand-in servers that answer like the real ones and sometimes fail on purpose, so you can practice handling failures. At the end, you build the friends’ planner from a brief.
You’ll type along in a terminal and any editor, with a current version of Node installed. The examples use Node 26. Make a folder for the planner and move into it:
$ mkdir planner
$ cd planner
To see the raw messages, you’ll use curl, a command-line tool that sends a request and prints what comes back. It comes with macOS, Windows 10 and later, and most Linux systems. On Windows, type curl.exe instead of curl, so that PowerShell runs the real tool. Its -i option, short for include, prints the response’s headers as well as its data.
Running curl is optional, as this lesson shows its output. Ask Nager.Date for Portugal’s 2026 holidays. The --http1.1 option asks for HTTP/1.1, the version of HTTP whose messages are lines of text you can read. The S in https means those lines travel encrypted, and curl decrypts them before it prints them:
$ curl --http1.1 -i https://date.nager.at/api/v4/Holidays/PT/2026
HTTP/1.1 200 OK
Date: Fri, 27 Nov 2026 13:19:42 GMT
Content-Type: application/json; charset=utf-8
...
Cache-Control: public,max-age=604800
...
Age: 462645
...
Server: cloudflare
...
[{"date":"2026-01-01","name":"New Year's Day","countryCode":
⮑ "PT","nationalHoliday":true,"subdivisionCodes":null,
⮑ "holidayTypes":["Public"]},{"date":"2026-02-17",
⮑ ...
This output is from a real run on November 27, 2026, cut where you see ... and wrapped at the ⮑ marks. Yours will show a different date and age, and more lines in the middle. Those are details of the moment. The parts you’ll label next are the same.
Label the Parts of Each Message
That screen of text is easier to read once you know that every HTTP/1.1 message has the same three-part shape: a first line that says what this message is about, then headers, then an optional body. Newer versions, HTTP/2 and HTTP/3, carry the same parts packed into binary frames, structured chunks of bytes, and curl prints them in this readable layout. The request and the response fill those parts in differently.
curl wrote the request for you, and -i doesn’t print it. Its -v option, short for verbose, shows it among many other details. Here are the request’s lines from the same run:
GET /api/v4/Holidays/PT/2026 HTTP/1.1
Host: date.nager.at
User-Agent: curl/8.5.0
Accept: */*
The first line, the request line, holds the method, the target, and the protocol version. GET means “send me this resource.” Other methods, such as POST to create something, come up later in the course. The target is part of the URL you typed. The URL splits into these pieces:
- Origin:
https://date.nager.at, the scheme, the host, and the port. It says which server to talk to and how. The port, which identifies a service on the server, isn’t written because HTTPS uses port 443 unless the URL names another. - Path:
/api/v4/Holidays/PT/2026, the resource on that server. The country code and the year are part of it. - Query string: Nothing here. When a URL has one, it starts at a
?, as in?format=json, and carries extra options.
The lines after the request line are headers, each a name, a colon, and a value. Host repeats the server’s name, User-Agent says which program is asking, and Accept: */* says that any format of answer is fine. A blank line ends the headers. Like most GET requests, this one has no body, so it ends there.
Now read the response from the top. Its first line is the status line. HTTP/1.1 is the protocol version, 200 is the status code, which says how the request went, and OK is a short phrase for people reading it. Every code from 200 to 299 is in the 2xx class, which means success.
The header that matters most for the planner is Content-Type: application/json; charset=utf-8. It labels the body: JSON, written in UTF-8 characters. Header names aren’t case sensitive, so Content-Type and content-type are the same header.
You can skip the rest for now. Cache-Control and Age are for caches, which keep copies of responses. These two headers say how long this copy counts as fresh and how old it already is. The others belong to the server and the network company in front of it.
After another blank line comes the body, which holds Portugal’s holidays as one long line of JSON. Here are both messages again, part by part:
If any of these parts is still fuzzy, ask the mentor to drill you on them. The button opens a chat with the question filled in, and the mentor will point at one part at a time and ask you what it says:
Read the Body as Text
The response’s body looks like an array of holiday objects, and the planner will need that array. Watch out, though. A body never arrives as a JavaScript object or array. It’s text, or raw bytes, with a Content-Type header naming its format. Something has to parse it before your code can read a property.
Before you test that, save a copy of the body. It’s the course’s fallback. When Nager.Date is down or slow, later lessons can read this file instead. Have curl write the body to a file with its -o option, short for output, and leave out -i so the headers stay out of it:
$ curl -o holidays-PT-2026.json https://date.nager.at/api/v4/Holidays/PT/2026
Copy this into a file named holidays-PT-2026.json in your planner folder. It’s the body Nager.Date sent on November 27, 2026, spread over several lines so it’s easier to read. curl saves it on one line, and either file works the same:
holidays-PT-2026.json
[
{
"date": "2026-01-01",
"name": "New Year's Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-02-17",
"name": "Carnival",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Optional"
]
},
{
"date": "2026-04-03",
"name": "Good Friday",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-04-05",
"name": "Easter Sunday",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-04-25",
"name": "Freedom Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-05-01",
"name": "Labour Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-06-01",
"name": "Azores Day",
"countryCode": "PT",
"nationalHoliday": false,
"subdivisionCodes": [
"PT-20"
],
"holidayTypes": [
"Public"
]
},
{
"date": "2026-06-04",
"name": "Corpus Christi",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-06-10",
"name": "National Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-07-01",
"name": "Madeira Day",
"countryCode": "PT",
"nationalHoliday": false,
"subdivisionCodes": [
"PT-30"
],
"holidayTypes": [
"Public"
]
},
{
"date": "2026-08-15",
"name": "Assumption Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-10-05",
"name": "Republic Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-11-01",
"name": "All Saints Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-12-01",
"name": "Restoration of Independence",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-12-08",
"name": "Immaculate Conception",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-12-25",
"name": "Christmas Day",
"countryCode": "PT",
"nationalHoliday": true,
"subdivisionCodes": null,
"holidayTypes": [
"Public"
]
},
{
"date": "2026-12-26",
"name": "St. Stephen's Day",
"countryCode": "PT",
"nationalHoliday": false,
"subdivisionCodes": [
"PT-30"
],
"holidayTypes": [
"Public"
]
}
]
To see what a program holds before anything parses the body, open the Node REPL, its interactive JavaScript prompt, for a moment: type node in your terminal. Then store the start of that body in a string. The string holds the first holiday, cut down to its date and English name, and ends with }] so it’s still valid JSON. The backticks make it a template literal, so the apostrophe in New Year’s needs no escaping:
> const body = `[{"date":"2026-01-01","name":"New Year's Day"}]`;
undefined
> typeof body
'string'
> body.length
47
> body[0]
'['
> body[0].name
undefined
> const holidays = JSON.parse(body);
undefined
> holidays[0].name
"New Year's Day"
typeof reports a string, and .length counts its characters, not holidays. body[0] is the first character of the text, [. A string has no .name property, so body[0].name gives undefined instead of throwing. That quiet undefined is what a program sees when it reads an unparsed body as if it were data.
What turns the text into data is JSON.parse(). It reads the string and returns a new value, an array holding one holiday object, which you stored in holidays. body itself is still a string, and holidays[0].name reads New Year’s Day. Type .exit to leave the REPL.
Back in the response, notice what didn’t happen. The Content-Type header didn’t convert anything. It’s a label that tells you which parser to reach for, the same way the .json at the end of the filename does. When you send requests from JavaScript later in the course, the body isn’t holiday data yet either. You’ll call a method that reads it as text, or one that reads it and parses it as JSON.
To test the idea, ask the mentor what would happen if the label and the text disagreed:
Check Your Reading
These questions use a request the planner will send to the World Bank’s countries API later in the course. The request asks for Portugal’s name and capital city. Here’s the command and its output, cut at the ... marks:
$ curl --http1.1 -i "https://api.worldbank.org/v2/country/PT?format=json"
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
...
Cache-Control: public, max-age=86400
...
[{"page":1,"pages":1,"per_page":"50","total":1},[{"id":"PRT",...
With -v, curl also showed the request line and host it sent:
GET /v2/country/PT?format=json HTTP/1.1
Host: api.worldbank.org
- What are the request’s method, origin, path, and query string?
- What’s the status code, which class is it in, and what does that class mean?
- Which header tells you the body’s format, and what format is it?
- A script reads this body as text into
body, without parsing it. What doestypeof bodygive, and what doesbody[0].pagegive?
- The method is
GET. The origin ishttps://api.worldbank.org, with HTTPS’s port 443 implied. The path is/v2/country/PT, and the query string is?format=json. - The status code is
200, in the 2xx class, which means the request succeeded. - The
Content-Typeheader saysapplication/json, so the body is JSON text. typeof bodygives"string".body[0]is the character[, sobody[0].pagegivesundefined. Parse it first, as inconst countries = JSON.parse(body);. Thencountries[0]is the object withpage: 1.bodyitself stays a string.
You’ve now read one exchange part by part, and you know that the body is text with a label until a parser turns it into data. The status line held a 200 this time, but a server can return many other status codes. In the next lesson, Sort Status Codes by Class, you’ll learn what each class of status code tells you and who has to act on it.