Fetch and JSON

Knowledge Videos

Short animated explainers, organised by subject.

Fetch and JSON

The browser is the client and fetch sends the request. The server answers with JSON, async and await wait for it, and the Network tab shows what happened.

Transcript

In the internet lessons you met the client and the server. In JavaScript, the browser is the client, and fetch is how it sends a request.

You give fetch a web address. The server sends back a response. Often the answer is J S O N, data written as text, and the json method turns it into an object you can use.

Fetch takes time, because the answer comes from far away. With async and await, the code waits at that line until the answer arrives, instead of racing ahead.

Then you use the data, for example to show a fact on the page. If the server is down, the code should show a friendly message instead. In DevTools, the Network tab shows each request and its response.

Remember: fetch asks a server for data. The response often comes as J S O N, await waits for the answer, and the Network tab shows what happened.

More in this series