HttpDefinition
Type, in @jr2/orchestrator/src/http-effect.ts. The signature of an export, or a type that it names, names this type. The Authoring surface page lists each export. This type is not an export of @jr2/orchestrator, so a workflow module does not import it by name.
type HttpDefinition<S extends z.ZodType | undefined = undefined> = {
method: HttpMethod;
url: string | Text | typeof open;
headers?: Readonly<Record<string, string | Text>>;
auth?: { readonly bearer: Secret } | { readonly basic: { user: Text; password: Text } } | Text;
input?: S;
request?: (input: S extends z.ZodType ? z.infer<S> : void) => HttpRequestParts;
body?: FileBody<S>;
timeout?: Duration;
maxBody?: number;
idempotent?: boolean;
};An http Effect's definition.
Fields
method:HttpMethodThe HTTP method:
GET,HEAD,POST,PUT,PATCH,DELETEorOPTIONS. It refuses another:http({ method: "<method>" }): the method is one of GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS.url:string | Text | typeof openThe url:
http://orhttps://, then a literal host. No input, param or Effect secret can change where the call goes. An Effect secret can be only in the path:text`https://api.telegram.org/bot${secret("tg")}/sendMessage`.Or
open: a packaged Machine that cannot know the host leaves the url Open, and the composer binds it one time withcustomize(machine, { effects: { <slot>: { url } } }).It refuses:
- a scheme or host that is not literal:
http({ url }): the url is an http:// or https:// url whose scheme and host are literal — a secret may sit only in its path, after a "/": text`https://api.example.com/bot${secret("tg")}/send` (ADR-0068) - an Effect secret after
?or#:http({ url }): secret("<name>") sits in the url's query or fragment — a secret may sit only in its path; send it in `auth` or a header instead: headers: { "x-api-key": text`${secret("...")}` } (ADR-0068) - a host that is not a host:
http({ url }): "<scheme>://<host>" is not a host - a user name or password in the url:
http({ url }): the url carries userinfo — use `auth`
- a scheme or host that is not literal:
headers(optional):Readonly<Record<string, string | Text>>Headers that are the same for each run. Each name is lowercase. A value is a string, or a
textwith an Effect secret.It refuses:
- a name that is not lowercase, or that frames or routes the request (
host,content-length,transfer-encoding,connection,upgrade,te,trailer,keep-alive,proxy-*):http({ headers }): "<name>" is not a header an Effect sets — a lowercase name that does not frame or route the request (ADR-0068) - an
authorizationheader besideauth:http({ headers }): "authorization" is set by `auth` — write one of them
- a name that is not lowercase, or that frames or routes the request (
auth(optional):{ readonly bearer: Secret; } | { readonly basic: { user: Text; password: Text; }; } | TextThe
Authorizationheader:bearer(secret("x")),basic(user, password), or atextthat is the whole value.input(optional):SThe zod schema of the input of the Effect: what the
inputof theinvoke, orfromPick, gives it. jr2 parses the input with it before the call. When it starts, input that does not agree with it makes the Effect fail (itsonErrorroute):http "<slot>": its input does not match the definition's input schema — <path>: <message>, one<path>: <message>for each problem, joined by;.request(optional):(input: S extends z.ZodType ? z.infer<S> : void) => HttpRequestPartsA function that makes the part of the request that changes for each run, from the input:
pathsegments, and ajsonortextbody. It cannot change the host, a header or an Effect secret. Do not write it besidebody.body(optional):FileBody<S>A Worktree file as the body:
file(path, { slot?, segments?, contentType? }). The Effect then runs in the Sandbox Effector of its Workspace. Do not writerequestbeside it: thesegmentsoffileare the path. It refuses another body:http({ body }): a body is file(path, { slot?, segments?, contentType? }) — json and text come from `request`.timeout(optional):DurationHow long jr2 waits for the answer: a number and a unit, such as
"30s"or"2m". Default"30s". With no answer in that time, the output isunknown. It refuses a value that is not a positive duration:http: timeout "<timeout>" is not a positive duration (like "30s", "2m").maxBody(optional):numberThe largest number of bytes of a text response body that the output keeps. Default 65536. When jr2 cuts the body,
truncatedistrue. It refuses a value that is not a positive whole number:http({ maxBody }): a positive number of bytes.idempotent(optional):booleantruewhen it is safe to send the call two times: it has its own idempotency key, or it only reads. Defaultfalse. After an Orchestrator restart, jr2 cannot always tell if the call went out. Then it sends an idempotent call again, and gives any other call the outputunknown.