Making GET Requests
Fetch data and parse JSON responses.
Making GET Requests is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What fetch Does
The Fetch API makes HTTP requests from the browser and returns a Promise. It is the modern replacement for the old XMLHttpRequest.
A Basic GET
Call fetch(url) with a URL. It defaults to the GET method and resolves with a Response object.
fetch("https://api.example.com/users")
.then((response) => {
console.log(response.status); // 200
});The Response Object
The resolved value is a Response, not the data itself. It carries status, headers, and methods to read the body. You must call a body method to get the content.
fetch(url).then((response) => {
console.log(response.ok); // true if status 200-299
console.log(response.status); // 200
});Parsing JSON
Most APIs return JSON. Call response.json(), which itself returns a Promise resolving to the parsed object.
fetch(url)
.then((response) => response.json())
.then((data) => {
console.log(data); // parsed JS object/array
});Why Two Promises
The first Promise resolves when headers arrive; the second (.json()) resolves when the full body is downloaded and parsed. That is why you chain two .then() calls.
Using async/await
Most code uses async/await for readability. Each await pauses until its Promise resolves.
async function getUsers() {
const response = await fetch(url);
const data = await response.json();
return data;
}Other Body Readers
Besides json(), a Response can be read as text(), blob() (binary), arrayBuffer(), or formData(). Choose based on what the server returns.
const response = await fetch(url);
const html = await response.text(); // raw stringBody Is Read Once
A response body is a stream you can consume only once. Calling json() then text() on the same response throws. Clone with response.clone() if you truly need both.
Query Parameters
Build query strings safely with URLSearchParams instead of concatenating by hand. It encodes special characters for you.
const params = new URLSearchParams({ page: 2, q: "hello world" });
fetch("https://api.example.com/search?" + params);Sending Headers
Pass a second argument with options. For GET you often set an Accept header or an auth token.
fetch(url, {
headers: {
"Accept": "application/json",
"Authorization": "Bearer " + token
}
});Returning the Promise
Wrap fetch logic in a function that returns the Promise so callers can await it. This keeps data-loading reusable across your app.
function loadUser(id) {
return fetch("/api/users/" + id).then((r) => r.json());
}Quick Check
GET requests with fetch.
Recap
fetch(url) returns a Promise for a Response. Read the body with json(), text(), or blob() (only once). Use async/await for clarity, URLSearchParams for query strings, and an options object for headers. Wrap it in functions that return the Promise for reuse.
Frequently asked questions
Is the “Making GET Requests” lesson free?
Yes — the full text of “Making GET Requests” is free to read here on the web, and the JavaScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Making GET Requests”?
Fetch data and parse JSON responses. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start JavaScript Academy?
No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Making GET Requests” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this JavaScript Academy lesson?
Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.