actions/transports_http.ts

HTTP transport — sends JSON-RPC messages via HTTP POST, or GET for a read whose params can ride the URL.

view source

Declarations
#

3 declarations

DEFAULT_MAX_GET_URL_LENGTH
#

actions/transports_http.ts view source

4096 import {DEFAULT_MAX_GET_URL_LENGTH} from '@fuzdev/fuz_app/actions/transports_http.js';

The longest path and query a read is sent as a GET with — 4096 characters. Past it the call goes as a POST: a cell_list naming its full id cap runs over it, and proxies refuse a request line past their own limit (nginx's default 8 KiB buffer) with a 414 the RPC client could not read.

FrontendHttpTransport
#

actions/transports_http.ts view source

import {FrontendHttpTransport} from '@fuzdev/fuz_app/actions/transports_http.js';

Thin fetch adapter for the JSON-RPC endpoint. POST by default; a request for a read — its spec (lookup_action_spec) has `side_effects: false — is a GET with method, id, and params` in the query string (matching create_rpc_endpoint's GET convention), unless its input carries a sensitive value (schema_has_sensitive_field, checked once per spec) or its path and query run past max_get_url_length. A notification, and a call for a method without a spec, is always a POST. Always reports ready.

On non-OK HTTP responses, a body that is a JSON-RPC error response for this request (same id, or null when the server couldn't read one) is returned as-is, so the server's code, message, and data reach the caller — the status → code map is lossy (queue_overflow and rate_limited share 429). Any other body (HTML from a proxy, empty, malformed) gets a synthesized envelope whose code comes from http_status_to_jsonrpc_error_code. A 2xx whose body isn't a JSON-RPC response (an HTML fallback page, say) becomes an internal_error naming the status and content type.

inheritance

implements: Transport

transport_name

type "frontend_http_rpc"

readonly

constructor

type new (options: FrontendHttpTransportOptions): FrontendHttpTransport

options

send

type (message: { method: string; jsonrpc: "2.0"; id: string | number; params?: ({} & Record<string, unknown>) | undefined; } & Record<string, unknown>, options?: TransportSendOptions | undefined): Promise<...>

message

options?

optional
returns Promise<JsonrpcResponseOrError>

is_ready

type (): boolean

returns boolean

FrontendHttpTransportOptions
#

actions/transports_http.ts view source

FrontendHttpTransportOptions import type {FrontendHttpTransportOptions} from '@fuzdev/fuz_app/actions/transports_http.js';

url

The JSON-RPC endpoint, absolute or relative to the page.

type string

headers?

Extra headers, merged over the JSON content-type and accept defaults case-insensitively — a POST without application/json is refused (415). A GET carries no content-type.

type Record<string, string>

lookup_action_spec

The spec of a method, which decides how its calls are sent: a request for a read (side_effects: false) is a GET, unless its input carries a 'secret' or 'personal' value at any depth (schema_has_sensitive_field) — a GET puts the params in the URL, which proxies and server logs record, so that input stays in a POST body. Every other call is a POST, including one for a method the lookup doesn't know. create_frontend_rpc_client passes its registry's lookup; a hand-built transport passes the same one its dispatcher environment uses.

type (method: string): ActionSpecUnion | undefined

method

type string
returns ActionSpecUnion | undefined

max_get_url_length?

The longest path and query a read is sent as a GET with; a longer one is a POST.

type number

default DEFAULT_MAX_GET_URL_LENGTH

Depends on
#

Imported by
#