Installation and the First Request¶
Contents | Previous: HTTP Client Overview | Next: Making Requests
View in another language — C++ · C#/.NET · Java · Kotlin · Node/TypeScript
After reading this chapter
You can add the HTTP client package to a project, receive a typed GET response through one client, and choose a one-shot for a single request.
The HTTP client ships separately from the server framework. A calling process needs only the HTTP client package. The tutorial below creates a client and reads one profile.
1. Package Reference¶
Each tab shows where that language references the package. The Java and Kotlin tabs quote the tutorial's actual Gradle dependencies, while Node/TypeScript installs the public npm package.
2. Client Creation and the First GET Request¶
A builder holding the base URL and default options creates a client. A request builder is created when a method such as GET or POST is selected from the client. A typed response terminator decodes the JSON body to the requested type and returns the response envelope. An asynchronous terminator does not occupy a thread or event loop while it waits for the result.
const client = ZLinkHttpClient.create(clientBaseUrl).timeout(3000).build();
const first = await client.get('/players/p1/profile').submit<PlayerProfile>();
console.log(`first request: ${first.body.playerId} ${first.body.nickname}`);
The code creates a client with a three-second default timeout, sends a profile GET request, and prints the player ID and nickname from the typed response body.
3. Result¶
The output below comes from the tutorial (framework/languages/node/tutorial) HttpClient with its Server and Client started as described in the README's "Run" section; the address is the Client's HTTP surface.
The captured runs for four languages show the same player ID and nickname. The C++ result remains reserved for the #714 fix.
4. A Single Request¶
A one-shot obtains its request builder directly from the client builder. It closes the client after completion, so it does not reuse a connection pool. A service that calls the same API repeatedly keeps a client as in the preceding section.
Next Chapter¶
Making Requests sets methods, paths, queries, headers, and per-request timeouts. Handling Responses chooses a response form, and Client and Request Lifecycle covers reuse and closing.