Skip to content

HTTP Client Overview

Contents | Next: Installation and the First Request

After reading this chapter

You can decide when an application inside or outside the server framework should use the HTTP client for an external HTTP API, and know its boundary.

The HTTP client is a client-side library that sends application requests to an external HTTP API and receives responses. The five languages differ only in names and notation; they provide the same semantics for building requests and choosing responses.

1. Where to Use the HTTP Client

A handler in the server framework, a CLI, a batch process, and a separate client process can all call an external HTTP API. A repeated-call application creates one client and reuses it. A single call can use a one-shot, which builds a request directly from the builder.

↗ 크게 보기

The following example previews the first request with a typed response. A typed response contains the status, headers, and a JSON-decoded body.

var first = await client.Get("/players/p1/profile").Async<PlayerProfile>();
Console.WriteLine($"first request: {first.Body.PlayerId} {first.Body.Nickname}");

All five examples use the same builder semantics to send a profile GET request, decode its JSON body as a typed PlayerProfile response, and read the player ID and nickname.

2. Boundary with the Server HTTP Surface

The HTTP client calls an external API. It does not open server HTTP routes or receive server requests, and it is not a browser replacement for fetch.

The HTTP client provides request methods, headers, bodies, and response rules. The external API's routes, authentication policy, and request and response DTOs belong to the application.

3. Tutorial Flow

The HttpClient tutorial for each language runs client creation, JSON requests, response forms, authentication, streams, and errors in one process. Its first step is Installation and the First Request.

Next Chapter

Installation and the First Request adds the package and runs the first GET request.