Skip to content

Template

Builds HTTP response text from template literals.

Template interpolations can be plain values, optional values, effects, or streams. The resulting effect or stream keeps the errors and service requirements from any effectful interpolations, which lets response helpers assemble dynamic text without losing type information.

7 exports Added in v4.0.0 Source

Constructors

make

Added in v4.0.0 Source

Creates an effectful string from a template literal.

Details

Primitive and Option interpolations are rendered immediately. Effect interpolations are evaluated and rendered before the final string is produced.

Signature

declare function make<A extends readonly Array<Interpolated>>(strings: TemplateStringsArray, ...args: A): Effect<string, Error<A[number]>, Context<A[number]>>

stream

Added in v4.0.0 Source

Creates a stream of strings from a template literal.

Details

Static text is emitted with interpolated values. Effect interpolations are evaluated as stream chunks, and stream interpolations are flattened into the output.

Signature

declare function stream<A extends readonly Array<InterpolatedWithStream>>(strings: TemplateStringsArray, ...args: A): Stream<string, Error<A[number]>, Context<A[number]>>

Models

Interpolated type

Added in v4.0.0 Source

Value accepted by the string template constructor.

Details

Interpolations can be primitive values, optional primitive values, or effects that produce primitive values.

Signature

type Interpolated = Primitive | Option.Option<Primitive> | Effect.Effect<Primitive, any, any>;

Value accepted by the streaming template constructor.

Details

In addition to normal interpolations, stream interpolations can emit primitive values over time.

Signature

type InterpolatedWithStream = Interpolated | Stream.Stream<Primitive, any, any>;

Primitive type

Added in v4.0.0 Source

Primitive template interpolation value.

Details

Arrays are rendered by converting each element to a string and concatenating the results.

Signature

type Primitive = PrimitiveValue | ReadonlyArray<PrimitiveValue>;

PrimitiveValue type

Added in v4.0.0 Source

Primitive value that can be interpolated into an HTTP template.

Signature

type PrimitiveValue = string | number | bigint | boolean | null | undefined;

Other

Interpolated

Added in v4.0.0 Source

Namespace containing type-level helpers for template interpolations.