Skip to content
CryoCryo home
Stdlibnet::http

client

import std::net::http::client; · source

Client

type struct Client {
    static new() -> Client;
    async get(&this, addr: SocketAddr, path: Str) -> Result<Response, IoError>;
    async post(&this, addr: SocketAddr, path: Str, content_type: Str, body: Array<u8>) -> Result<Response, IoError>;
}
async function send(addr: SocketAddr, req: Request) -> Result<Response, IoError>;
import std::net::http::client;

mut c: Client = Client::new();
const resp = ex.block_on(c.get(addr, Str::new("/health")));

get and post are one-shot: connect, send, read the response, close. The free send sends a request you built yourself. The Host header is filled in from the address automatically, and Connection: close is set so the server does not hold the connection for keep-alive.

For HTTPS, net::https wraps the same machinery with TLS underneath.