Your bookmarks

Loading your bookmarks

Latest updates

New courses, skills, book chapters, and site improvements will appear here.

Create free accountSign upDashboardDashboard

Request and response

  • Standard term
3 steps

A request and response is one round trip between programs: a client (the program doing the asking) asks a server for something, and the server may reply with the result and a status code saying how it went.

The request names an action, such as "save this note," and carries the details the server needs, often with a sign-in key showing who is asking. The reply opens with a status code, where 200 means it worked and 401 means the key wasn't accepted. Sometimes no reply arrives, because the connection dropped or the server took too long.

Where you’ll meet it

Each morning, the personal assistant you built asks your calendar service for today's meetings. Its sign-in key expired last week, so the service replies with a 401 and an error message. The assistant reads the reply as an empty list and tells you your day is clear.

What to do

Ask your coding agent to make the assistant check the status code first, and when a reply isn't a success, tell you what went wrong, such as "Calendar sign-in expired," in place of an empty day. Then have the agent try it with an expired key, and read the message you get.

Easy to mix up

A webhook starts with the other service, which calls your app when an event happens there. A request starts with your app, whenever it wants an answer.

Check yourself

Your app sends "charge $40 for the field trip" to a payment service. The connection drops before any reply arrives. What should the app do next?

Go deeperStatus codes come in families, and each request stands on its own

The first digit of an HTTP status code gives its family. 2xx means success, 4xx a problem with the request, such as 404 for an address that doesn't exist or 429 for too many requests, and 5xx a failure on the server. Some services return 200 with an error message inside, so a careful client also reads the content that comes with the code.

HTTP is stateless, meaning the protocol links no request to the ones before it. A service that needs to know who is asking has to be told again each time, usually in a header, a labeled line sent ahead of the main content. Staying signed in to a website works the same way, with the browser sending a cookie, a small saved note that identifies you, on every request.

Practice Build Basics

Or take the learning quiz on a mix of every set