Skip to main content

Module client

Module client 

Source
Expand description

Typed, fluent HTTP client.

This module provides a builder-oriented API for issuing HTTP requests against a configurable Target — a localhost port or an arbitrary remote base URL — and deserialising the response body into a concrete Rust type via serde.

The entry point is Client. Call any method constructor (get, post, etc.) to obtain a RequestBuilder. Optionally attach a JSON body via json or URL query parameters via query, then finalise with send (async) or send_sync (blocking). All seven standard HTTP methods are supported.

§Builder chains at a glance

ChainSends
client.method(endpoint).send().awaitplain request
.json(value).send().awaitContent-Type: application/json body
.query(params).send().awaitserialised query string

§Example

use toolkit_zero::socket::client::{Client, Target};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)] struct Item { id: u32, name: String }
#[derive(Serialize)] struct NewItem { name: String }
#[derive(Serialize)] struct Filter { page: u32 }

let client = Client::new(Target::Localhost(8080));

// Plain async GET
let items: Vec<Item> = client.get("/items").send().await?;

// POST with a JSON body
let created: Item = client
    .post("/items")
    .json(NewItem { name: "widget".into() })
    .send()
    .await?;

// GET with query parameters
let page: Vec<Item> = client
    .get("/items")
    .query(Filter { page: 2 })
    .send()
    .await?;

// Synchronous DELETE
let _: Item = client.delete("/items/1").send_sync()?;

Structs§

Client
HTTP client for making typed requests against a Target server.
EncryptedBodyRequestBuilder
A request builder that VEIL-seals the body before sending.
EncryptedQueryRequestBuilder
A request builder that VEIL-seals query params and sends them as ?data=<base64url>.
JsonRequestBuilder
A request builder that will send a JSON-serialised body.
QueryRequestBuilder
A request builder that will append serialisable query parameters to the URL.
RequestBuilder
A request builder with no body or query parameters attached.

Enums§

ClientError
Error returned by EncryptedBodyRequestBuilder and EncryptedQueryRequestBuilder.
Target
The target server for a Client.

Attribute Macros§

request
Concise HTTP client request for toolkit-zero socket-client routes.