Examples ​
This section contains practical httpx.zig demo programs for client, server, middleware, streaming, and protocol features.
How to Use ​
- Open an example page.
- Review the
Demo Programsnippet. - Run the matching command from the
Runsection. - Verify behavior with the checklist.
For non-host targets, compile (without running) by adding -Dtarget=...:
bash
zig build example-tcp_local -Dtarget=x86_64-linux
zig build example-http3_example -Dtarget=aarch64-macosAvailable Examples ​
- Simple Get: Basic GET request and response handling.
- Simple Get Deserialize: Parse JSON into typed structs.
- HTTP Auth Helpers: Use built-in Bearer and Basic auth request helpers against a local loopback server.
- Post JSON: Send JSON payloads with POST.
- Custom Headers: Attach auth and custom metadata headers.
- Concurrent Requests: Execute multiple requests in parallel.
- Connection Pool: Reuse pooled connections efficiently.
- Interceptors: Apply request and response interceptors.
- Cookies Demo: Manage cookie jar values in client flows.
- Logging Callback: Set up custom logging functions for both server and client.
- Proxy and Reverse Proxy: Configure client forward proxies, including SOCKS5h tunnels, and register reverse proxy middleware.
- SOCKS5h Proxy: Route requests through a SOCKS5h proxy with remote DNS resolution.
- Simplified API Aliases: Use short top-level helper APIs with local loopback success mode by default.
- Simple Server: Start a minimal HTTP server.
- Thread Pool / Async Server: Start a concurrent HTTP server with thread pool connection dispatching.
- Router Example: Route params and grouped endpoints.
- Middleware Example: Chain middleware with shared behavior.
- Streaming: Stream data responses.
- SSE Example: Server-Sent Events formatting and streaming from server to client.
- Static Files: Serve assets with content types, ETag headers, and conditional GET (
If-None-Match) support. - Multi Page Website: Serve multiple HTML pages.
- HTTP/2 Example: HTTP/2 framing and stream primitives.
- HTTP/2 Client Runtime: End-to-end high-level HTTP/2 client request against a local loopback server.
- HTTP/2 Server Runtime: End-to-end high-level HTTP/2 server route consumed by a local HTTP/2 client.
- HTTP/3 Example: HTTP/3, QPACK, and QUIC primitives.
- HTTP/3 Client Runtime: End-to-end high-level HTTP/3 client request against a local UDP loopback server.
- HTTP/3 Server Runtime: End-to-end high-level HTTP/3 server route consumed by a local HTTP/3 client over UDP.
- HTTP/2 Advanced: HTTP/2 production features (SETTINGS enforcement, GOAWAY/RST_STREAM, HPACK security, trailers).
- HTTP/3 Advanced: HTTP/3 production features (QPACK stream instructions, QUIC stream cancellation, transport parameters).
- TCP Local: Local TCP listener/client round trip.
- UDP Local: Local UDP transport demo.
- WebSocket Example: Read upgrade headers, handshake keys, and process frame inputs.
- WebSocket Server: WebSocket handshake detection, frame encoding/decoding, and bidirectional messaging.
- Multipart Form Data: Build and parse multipart payloads with text fields and file uploads.
- Session Store: Set/get session data, evict sessions on TTL, and integrate with servers.
- Metrics and Observability: Aggregate total requests, status codes, latency times, and success rates.
- Unix Domain Sockets: Bind servers and connect clients over AF_UNIX sockets.
- Health Check Probes: Configure liveness and readiness probe middlewares.
- Cloud HTTPS Server: Production cloud deployment with TLS, middleware, and health checks.
- TLS Server: Custom TLS server with ALPN negotiation.
- HTTPS Client: HTTPS client with custom TLS configuration.
- Request Response Customization: Customize request properties and response headers.
- Compression: Gzip, deflate, brotli, and zstd compression/decompression.
- HTTP Methods: GET, POST, PUT, DELETE, HEAD, OPTIONS.
- Retry: Retry with exponential backoff.
- DNS Resolution: DNS cache and resolution.
- Redirect: Redirect following and policy.
- Batch Concurrent: Batch concurrent requests.
- Reverse Proxy Middleware: Server-side reverse proxy.
