So far, curl has built every request for you. You typed a URL, and it chose the method and the headers. That was enough for reading Portugal’s holidays, but the planner has more to do than read one list.
The planner will ask two different servers for data and will send the friends’ chosen weekend somewhere they can all see it. Before you write any of those requests in JavaScript, you need to know what each one should contain. In this lesson, you’ll turn a plain description of a task into a request: its method, its URL, its headers, its body, and the status codes you expect back. Start with the request you already know.
Read Data With GET
Every request answers the same few questions, as the holidays request from the first lesson shows. Here’s its request line and the one header worth choosing yourself, as the planner will send it:
GET /api/v4/Holidays/PT/2026 HTTP/1.1
Host: date.nager.at
Accept: application/json
Read it as a set of decisions. The task is “get Portugal’s holidays for 2026,” and getting is reading, so the method is GET. Nager.Date’s documentation puts the country code and the year in the path, so PT and 2026 go there. This GET request sends its inputs in the URL and has no body. The fetch() function you’ll use later goes further and refuses to send a GET with a body at all.
The Accept header says which formats you’d like the answer in. curl sent Accept: */*, meaning anything. The planner can only use JSON, so it sends Accept: application/json.
Last, decide what you expect back: 200 with the holidays, or a 404 if the API doesn’t recognize the country code, as XX showed in the last lesson.
The planner’s second request goes to the World Bank Countries API, which knows each country’s name and capital city. The task is “get Portugal’s name and capital.” It’s still reading, so it’s another GET. The country code goes in the path, and an option goes in the query string, the part of the URL after the ?:
$ curl --http1.1 -i "https://api.worldbank.org/v2/country/PT?format=json"
HTTP/1.1 200 OK
Date: Fri, 27 Nov 2026 07:31:14 GMT
Content-Type: application/json;charset=utf-8
...
set-cookie: __cf_bm=nCdA9mBNjU0tad9WeFopqqS...; HttpOnly; ...
set-cookie: _cfuvid=M3TJvrrap9JzhbUN6qMs6La...; HttpOnly; ...
...
Cache-Control: public, max-age=86400
...
[{"page":1,"pages":1,"per_page":"50","total":1},[{"id":"PRT",
⮑ "iso2Code":"PT","name":"Portugal","region":{"id":"ECS",
⮑ ...
⮑ "capitalCity":"Lisbon","longitude":"-9.13552","latitude":
⮑ "38.7072"}]]
This output is from a real run on November 27, 2026, cut at the ... marks and wrapped at the ⮑ marks. The quotes around the URL stop your shell from reading the ? as a special character. The body is an array with two elements: details about the list and a list containing one country. That country’s name is "Portugal", and its capitalCity is "Lisbon".
The path and the query string do different jobs. The path names the thing you want, here country PT. The query string adjusts how you get it, here the format. The API’s documentation specifies both, so you read it and follow it instead of guessing. You’ll read API docs in detail later in the course.
You saw earlier that Accept: application/json asks for JSON. So what if you leave out ?format=json and send that header instead? curl’s -H option adds a request header, and the quoted text gives its name and value. Make a guess, then open the box:
$ curl --http1.1 -i -H "Accept: application/json" https://api.worldbank.org/v2/country/PT
The answer is XML, another text format, and not JSON:
HTTP/1.1 200 OK
Date: Fri, 27 Nov 2026 07:32:18 GMT
Content-Type: text/xml
...
<?xml version="1.0" encoding="utf-8"?><wb:countries page="1"
⮑ ...
An Accept header is a request that a server can turn down. Many APIs honor it, but the World Bank’s ignores it and reads the format from the query string instead. The response’s Content-Type tells you what you actually got. So the planner sends both: Accept to state what it wants, and ?format=json because this API needs it.
If you’re still unsure when a value belongs in the path and when in the query string, ask the mentor. The button opens a chat with the question filled in:
You call the World Bank for the first time in this lesson, so save its answer as the course’s second fallback. You can use this file in later lessons when the API is down:
$ curl -o country-PT.json "https://api.worldbank.org/v2/country/PT?format=json"
Copy this into a file named country-PT.json in your planner folder. It’s the body the World Bank sent on November 27, 2026, spread over several lines so it’s easier to read:
country-PT.json
[
{
"page": 1,
"pages": 1,
"per_page": "50",
"total": 1
},
[
{
"id": "PRT",
"iso2Code": "PT",
"name": "Portugal",
"region": {
"id": "ECS",
"iso2code": "Z7",
"value": "Europe & Central Asia"
},
"adminregion": {
"id": "",
"iso2code": "",
"value": ""
},
"incomeLevel": {
"id": "HIC",
"iso2code": "XD",
"value": "High income"
},
"lendingType": {
"id": "LNX",
"iso2code": "XX",
"value": "Not classified"
},
"capitalCity": "Lisbon",
"longitude": "-9.13552",
"latitude": "38.7072"
}
]
]
The World Bank API can also take several codes in one path, such as PT;DE;JP;MX. The planner doesn’t use that form because one mistyped code spoils the answer for every country. It sends one request per friend to each API instead: four for the holidays and four for the countries, eight in all.
Send Data With POST
The planner has to write data too. Once the friends agree on a weekend, they want it saved in one place that all four of them can check. Saving means creating something new on a server, so you’ll use a different method.
Neither real API lets you do that. Both only support reading, and Nager.Date answers any other method with 405 Method Not Allowed and an allow: GET header naming the one method it takes. So the course gives the friends a trip board, a stand-in API that stores the weekends they pick, at https://trip-board.example/.
The trip board isn’t on the internet. Names ending in .example are reserved for examples and never reach a real server. Later lessons give you a small module, tripBoard.mjs, that answers requests to that address from inside your own program. It reads exactly what your request sends, so it shows whether you built the request right. That’s all you need about it for now.
The task is “save the weekend of May 1 to 3, 2026, which starts with Labor Day, a public holiday in Portugal, Germany, and Mexico.” That’s what POST is for. The data goes in a body this time, written as JSON, so the request needs a Content-Type header to label it, exactly as the responses labeled theirs:
POST /weekends HTTP/1.1
Host: trip-board.example
Content-Type: application/json
Accept: application/json
Content-Length: 70
{"start":"2026-05-01","end":"2026-05-03","countries":["PT","DE","MX"]}
The path, /weekends, names the collection the new weekend joins. Content-Length counts the body’s 70 bytes, and the client fills it in, so you never choose it. On success, the trip board answers 201 Created and sends back the weekend it stored, with an assigned id:
HTTP/1.1 201 Created
Content-Type: application/json
{"id":1,"start":"2026-05-01","end":"2026-05-03","countries":["PT","DE","MX"]}
GET and POST are the two methods the planner uses. Three more are worth recognizing. PUT replaces a stored thing with a new version, PATCH changes part of it, and DELETE removes it. If the friends moved the stored weekend’s end to Monday, then a PATCH to /weekends/1 with the new end date would describe that.
Choosing a method gets faster with practice. To try a few more, ask the mentor for tasks and name the method for each:
Make Each Request Complete
The planner sends nine requests, the eight reads and the POST that saves the weekend, and you might expect each one to pick up where the last left off. It doesn’t. A server can keep data, as the trip board keeps the weekends it stores, but it reads each HTTP request on its own. A request doesn’t inherit the earlier one’s options or headers, so it has to carry everything the server needs to answer it.
That’s why every World Bank request repeats ?format=json, and every holidays request names its country and year in the path. A POST sends its Content-Type every time for the same reason.
Websites that need to recognize you, such as a store with your shopping cart, work around this. Some hand your browser a cookie, a small piece of text that the browser sends back on later requests to the same site, within rules the cookie sets. Others ask for a key in a header.
The World Bank response set cookies for the network company in front of it, but the planner never sends them back, and Nager.Date and the World Bank answer anyway.
Here are the planner’s three kinds of request side by side:
| Task | Method | URL | Headers | Expect |
|---|---|---|---|---|
| Portugal’s 2026 holidays | GET |
https://date.nager.at/api/v4/Holidays/PT/2026 |
Accept: application/json |
200, or 404 for an unknown code |
| Portugal’s name and capital | GET |
https://api.worldbank.org/v2/country/PT?format=json |
Accept: application/json |
200 |
| Save the chosen weekend | POST |
https://trip-board.example/weekends |
Content-Type and Accept, both application/json |
201 |
Only the POST has a body. For any new request, ask the same things in the same order: what’s the action, where does each piece of data go, which headers describe the body and the answer you want, and which status codes should you expect?
Check Your Reading
Plan each request from its description:
- Get Japan’s public holidays for 2026. Give the method, the full URL, and the status code you’d expect if the API didn’t recognize the country code.
- Get Germany’s name and capital city. Give the method and the full URL.
- Save the weekend of December 25 to 27, 2026, which starts with Christmas Day, a public holiday in Portugal, Germany, and Mexico, on the trip board. Give the method, the URL, the headers, and the body, and say what each header tells the trip board.
- Explain why your answer to question 3 needs a
Content-Typeheader when your answers to 1 and 2 don’t.
- Send
GET https://date.nager.at/api/v4/Holidays/JP/2026withAccept: application/json. An unrecognized code, such asXX, gets404 Not Found. A typo that lands on another real code, such asDE, gets200with that country’s holidays instead. - Send
GET https://api.worldbank.org/v2/country/DE?format=json. Without?format=json, the answer is XML, whatever yourAcceptheader says. - Send
POST https://trip-board.example/weekendswith the body{"start":"2026-12-25","end":"2026-12-27","countries":["PT","DE","MX"]}.Content-Type: application/jsonsays the body is JSON, andAccept: application/jsonasks for JSON back. A success is201 Created. Content-Typedescribes a request’s body, and only thePOSThas one. TheGETrequests send no body, so there’s nothing to label.
In the course’s first coding exercise, you’ll write functions for the planner that read a response’s parts. They decide whether its body can be parsed as JSON and who has to act on its status.
Then you’ll describe the request each task needs. You’ll write and run the code in your browser, and automated tests will check it. The exercise’s Contents tab explains how coding exercises work. Go on to Exercise: Read Responses and Plan Requests.