Skip to content

Installation and the First Request

Contents | Previous: HTTP Client Overview | Next: Making Requests

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

// This process is outside the mesh and references only the HTTP client package.
implementation(libs.zlink.http.client)

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.

↗ 크게 보기

ZLinkHttpClient client =
        ZLinkHttpClient.create("http://127.0.0.1:5280")
                .timeout(Duration.ofSeconds(3))
                .build();
PlayerProfile first =
        client.get("/players/p1/profile")
                .fetch(PlayerProfile.class)
                .toCompletableFuture()
                .join();
System.out.println("first request: " + first.playerId() + " " + first.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/java/tutorial/java) HttpClient with its Server and Client started as described in the README's "Run" section; the address is the Client's HTTP surface.

first request: p1 rookie

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.