flare.http
HTTP/1.1 client and server.
Built on flare.tcp and flare.tls — no external HTTP library. Supports
persistent connections, redirects, chunked transfer encoding, gzip/deflate
decompression, and injection-safe header handling.
Public API
from flare.http import (
HttpClient, HttpServer,
Request, Response,
HeaderMap, HeaderInjectionError,
Url, UrlParseError,
Method, Status, Encoding,
HttpError, TooManyRedirects,
BasicAuth, BearerAuth,
get, post, put, delete, head,
)
HttpClient— Send HTTP/HTTPS requests:get,post,put, etc.HttpServer— Accept and dispatch HTTP requests.Request— HTTP request (method, URL, headers, body).Response— HTTP response (status, headers, body,text(),json()).HeaderMap— Case-insensitive HTTP header collection.HeaderInjectionError— Raised on CR/LF characters in header names or values.Url— Parsed HTTP/HTTPS URL (scheme, host, port, path, query).UrlParseError— Raised on invalid URL syntax.Method— HTTP method string constants (GET,POST, …).Status— HTTP status code integer constants (OK,NOT_FOUND, …).Encoding— Content-Encoding token constants (gzip,deflate).HttpError— Raised byResponse.raise_for_status()on non-2xx responses.TooManyRedirects— Raised when the redirect limit is exceeded.BasicAuth— HTTP Basic authentication (RFC 7617).BearerAuth— HTTP Bearer token authentication (RFC 6750).Extractor— Trait implemented by each extractor.PathInt,PathStr,PathFloat,PathBool,QueryInt,QueryStr,QueryFloat,QueryBool,OptionalQueryInt,OptionalQueryStr,OptionalQueryFloat,OptionalQueryBool,HeaderInt,HeaderStr,HeaderFloat,HeaderBool,OptionalHeaderInt,OptionalHeaderStr,OptionalHeaderFloat,OptionalHeaderBool— Concrete typed extractors for path params, query string, headers. Each exposes.valueas the parsed primitive directly. Custom types are handled by writing your ownExtractorstruct.Peer— Extracts the kernel-reported peerSocketAddrpopulated by the reactor at accept time.BodyBytes,BodyText,Json,Cookies,Form,Multipart— Extractors that read the request body.FormData,parse_form_urlencoded,urlencode,urldecode—application/x-www-form-urlencodedparsing helpers.MultipartPart,MultipartForm,parse_multipart_form_data—multipart/form-dataparser (RFC 7578).Extracted— Reflective auto-injection wrapper: put your extractor set on the fields of anyHandlerstruct (plusDefaultable) and wrap it inExtracted[H]to get aHandlerthat pulls each field from the request before calling the innerserve.ComptimeRoute,ComptimeRouter— Comptime-compiled route table: segment parsing runs at compile time and the dispatch loop unrolls per route. Same 404 / 405 contract asRouter, parametric over a comptimeList[ComptimeRoute].StaticResponse,precompute_response— Pre-encoded literal HTTP responses. Pair withHttpServer.serve_static(resp)for the fastest possible fast path: the reactor parses requests only far enough to find the terminator, thenmemcpys the canned bytes into the write queue. NoRequest, no handler, no response serialisation.get,post,put,delete,head— Module-level one-shot helpers.postandputaccept aString(JSON auto-set),json.Value(auto-serialised), orList[UInt8](raw bytes).
Example
from flare.http import HttpClient, BasicAuth, BearerAuth, get, post
def main() raises:
# One-shot GET
var resp = get("https://httpbin.org/get")
print(resp.status) # 200
# One-shot POST — String body sets Content-Type: application/json automatically
post("https://httpbin.org/post", '{"k": 1}').raise_for_status()
# Session with base URL + auth — no repeated URL prefix
with HttpClient("https://httpbin.org", BasicAuth("alice", "s3cr3t")) as c:
var r = c.get("/basic-auth/alice/s3cr3t")
r.raise_for_status()
print(r.text())
# Parse JSON response body (returns json.Value)
var data = HttpClient().get("https://httpbin.org/json").json()
print(data["slideshow"]["title"].string_value())