Skip to main content

Module http_client

Module http_client 

Source
Expand description

bynk client (#3508, slice BC1): the typed TypeScript client for a project’s from http services, one module a front end imports.

The command in bynk/src/http_client.rs reads each route’s facts from the checked project (the wire-contract peek bynk openapi reads) and hands them over as an HttpClientInput; this module turns them into the module’s text.

§One codec, one source of truth

Nothing here is a second implementation of the boundary. The codecs are the ones a Bynk consumer generates for a callee’s types (serialisation::emit_helpers_for_owner_qualified under a qualifier, which inlines a transparent refinement’s check and casts an opaque one), and each call site names them through serialise_expr_via / deserialise_ref_via, exactly as the foreign-caller client (client.rs, #1970) does. What differs is the half the codec does not own:

  • Optional values are T | null in the generated types (the maintainer’s decision on #3508), not Bynk’s tagged Option. The codecs still speak Option, so each boundary type is declared twice: the wire type (__Wire_Order, what a codec produces and consumes) and the public type (Order, what a caller sees), with a generated function per type between them. A type with no Option reachable has no conversion, and the two are the same shape.
  • Refinements are checked on the way out by running the decoder over the value just encoded, so the predicates are the server’s own and a violation is returned as CallFailure before anything is sent. On the way in the response is decoded by the same codecs.
  • A route’s answer is a union keyed by status, built from the response set bynk openapi documents, and never thrown.

The runtime half is http_client_runtime.ts (generated from runtime/src/client/http_client.ts by bundle.mjs), inlined: a browser-safe subset with no signing and no Workers types, plus the runtime’s own result, bytes, decimal and keys modules for just the names the codecs use.

Structs§

ClientError
Why a client cannot be generated.
Emitted
The client, and the routes it leaves out with why.
HttpClientInput
What the command hands the generator.
ReplyInput
One answer a route can make, in bynk openapi’s terms.
RouteInput
One route of a service.
ServiceInput
One from http service.

Enums§

BodyKind
How a route reads its body.
Layout
How the client is laid out.
ParamInput
What a route takes.
ReplyPayload
What an answer’s body carries.

Constants§

DIR_FILES
The files of a directory layout, in the order they are written.
SINGLE_FILE
The file name a single-file client has in Emitted::files: the caller writes it wherever --out says.

Functions§

emit_http_client
The module for input. A route whose types have no T | null form (an Option inside a Map, Set or Result, or an Option[Option[T]]) is left out and named, never emitted wrong.
function_name
GET /orders/:id is getOrderById; POST /orders is postOrders. A static segment before a parameter is singular (orders/:id reads “order by id”). A route has no name of its own to use (#3508 open question 4).