Contenu du cours
Module 1 — Discovering JavaScript
What JavaScript does, where to write your code, the console and a first script.
0/4
Module 2 — Language fundamentals
Variables and types, operators and conditions, then loops.
0/4
Module 3 — Functions and interactivity
Writing functions, responding to events and manipulating the DOM.
0/4
Module 4 — Going further
Arrays and objects, an introduction to APIs with fetch, and best practice.
0/4
JavaScript for beginners

Modern sites exchange data with servers: weather, news, products and so on. Those exchanges go through APIs, and JavaScript queries them with fetch.

What is an API?

An API is a service that supplies data on request. You send a request to an address and it sends back a response, usually in JSON format (structured text that code can read easily).

Using fetch

fetch("https://api.exemple.com/donnees")
  .then(reponse => reponse.json())
  .then(donnees => console.log(donnees));

Here is what happens, step by step:

  • fetch sends the request to the address you give it.
  • .json() turns the response into usable data.
  • The second .then finally receives that data so you can work with it.

Because the response can take a while, these operations are asynchronous: the code does not wait around and handles the result as soon as it arrives.

Key takeaway: fetch retrieves remote data through an API. The response comes back later: you handle it with .then.

Prix indicatifs, convertis depuis l'euro