Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Calling Web APIs With fetch (Summary)

You’ve finished Calling Web APIs With fetch, the last course on this path.

In This Course, You Learned How To

  • Read the HTTP requests and responses that travel over the wire
  • Make and inspect HTTP requests with fetch
  • Read an API’s docs, and combine data from real web APIs
  • Handle failed requests, slow responses and missing data
  • Build a long weekend planner for four friends abroad

From the Wire to fetch()

A request and its response each have a first line and headers, and may have a body.

When Mateo typed XX, Nager.Date answered 404, and fetch() didn’t reject. Only response.ok said no, so your check threw an error. fetch() rejected with a TypeError when the request couldn’t complete.

URL and searchParams kept “Trinidad & Tobago” one value. A POST with a JSON body saved the friends’ weekend and got back 201 Created. A deadline signal stopped any request that took too long.

Working With Real APIs

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ve finished Calling Web APIs With fetch, the last course on this path. In this course, you learned how to: Read the HTTP requests and responses that travel over the wire.

00:12 Make and inspect HTTP requests with fetch. Read an API’s docs, and combine data from real web APIs. Handle failed requests, slow responses and missing data.

00:24 And build a long weekend planner for four friends abroad.

00:30 A request and its response each have a first line and headers, and may have a body.

00:37 When Mateo typed XX, Nager.Date answered 404, and fetch didn’t reject. Only response.ok said no, so your check threw an error. Fetch rejected with a TypeError when the request couldn’t complete.

00:52 URL and searchParams kept Trinidad and Tobago one value. A POST with a JSON body saved the friends’ weekend and got back 201, created. A deadline signal stopped any request that took too long.

01:08 You read the docs, then ran eight requests together, and Mateo’s failures stayed in Mateo’s results. For XX, the World Bank answered 200 with only an error message, so you checked every body’s shape.

01:24 Its country list came in six pages, so you followed them all to find Mateo’s real code, MX. You retried only what might succeed, with a wait and a cap. A 404 got only one request.

01:40 The planner put it all together and found two long weekends that Amara, Jonas and Mateo share.

01:48 Read and parse a JSON body before you use its data. Fetch rejects only when it gets no response, so check response.ok yourself. Build every URL with the URL class and searchParams, and give a JSON body its Content-Type header.

02:04 Check every body’s shape. Give every request a deadline, and retry only what might succeed.

02:13 Your next step is to keep growing the API program you built. Add the should feature from your review, then a could, the same way. For more on JSON, read JSON vs XML, and look it up in the RealJS reference.

02:30 Thanks for watching.

Become a Member to join the conversation.