Skip to content
Effect Days 2026 Get your ticket

HttpRouter

51 exports Added in v1.0.0 Source

Combinators

append

Added in v1.0.0 Source

Signature

declare const append: {
<R1, E1>(route: Route<E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, route: Route<E1, R1>): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

catchAll

Added in v1.0.0 Source

Signature

declare const catchAll: {
<E, E2, R2>(f: (e: E) => Handler<E2, R2>): <R>(self: HttpRouter<E, R>) => HttpRouter<E2, R | Exclude<R2, Provided>>;
<E, R, E2, R2>(self: HttpRouter<E, R>, f: (e: E) => Handler<E2, R2>): HttpRouter<E2, R | Exclude<R2, Provided>>;
}

Signature

declare const catchAllCause: {
<E, E2, R2>(f: (e: Cause<E>) => Handler<E2, R2>): <R>(self: HttpRouter<E, R>) => HttpRouter<E2, R | Exclude<R2, Provided>>;
<E, R, E2, R2>(self: HttpRouter<E, R>, f: (e: Cause<E>) => Handler<E2, R2>): HttpRouter<E2, R | Exclude<R2, Provided>>;
}

catchTag

Added in v1.0.0 Source

Signature

declare const catchTag: {
<K extends string, E, E1, R1>(k: K, f: (e: Extract<E, {
_tag: K;
}>) => Handler<E1, R1>): <R>(self: HttpRouter<E, R>) => HttpRouter<E1 | Exclude<E, {
_tag: K;
}>, R | Exclude<R1, Provided>>;
<E, R, K extends string, E1, R1>(self: HttpRouter<E, R>, k: K, f: (e: Extract<E, {
_tag: K;
}>) => Handler<E1, R1>): HttpRouter<E1 | Exclude<E, {
_tag: K;
}>, R | Exclude<R1, Provided>>;
}

catchTags

Added in v1.0.0 Source

Signature

declare const catchTags: {
<E, Cases extends {} | { [K in string]: (error: Extract<E, {
_tag: K;
}>) => Handler<any, any> }>(cases: Cases): <R>(self: HttpRouter<E, R>) => HttpRouter<Exclude<E, {
_tag: keyof Cases;
}> | { [K in string | number | symbol]: Cases[K] extends (...args: Array<any>) => Effect<any, E, any> ? E : never }[keyof Cases], R | Exclude<{ [K in string | number | symbol]: Cases[K] extends (...args: Array<any>) => Effect<any, any, R> ? R : never }[keyof Cases], Provided>>;
<R, E, Cases extends {} | { [K in string]: (error: Extract<E, {
_tag: K;
}>) => Handler<any, any> }>(self: HttpRouter<E, R>, cases: Cases): HttpRouter<Exclude<E, {
_tag: keyof Cases;
}> | { [K in string | number | symbol]: Cases[K] extends (...args: Array<any>) => Effect<any, E, any> ? E : never }[keyof Cases], R | Exclude<{ [K in string | number | symbol]: Cases[K] extends (...args: Array<any>) => Effect<any, any, R> ? R : never }[keyof Cases], Provided>>;
}

concat

Added in v1.0.0 Source

Signature

declare const concat: {
<R1, E1>(that: HttpRouter<E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R1 | R>;
<E, R, R1, E1>(self: HttpRouter<E, R>, that: HttpRouter<E1, R1>): HttpRouter<E | E1, R | R1>;
}

concatAll

Added in v1.0.0 Source

Signature

declare const concatAll: <Routers extends ReadonlyArray<HttpRouter<unknown, unknown>>>(...routers: Routers) => [Routers[number]] extends [HttpRouter<infer E, infer R>] ? HttpRouter<E, R> : never

prefixAll

Added in v1.0.0 Source

Signature

declare const prefixAll: {
(prefix: PathInput): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E, R>;
<E, R>(self: HttpRouter<E, R>, prefix: PathInput): HttpRouter<E, R>;
}

Signature

declare const provideService: {
<T extends Tag<any, any>>(tag: T, service: Service<T>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E, Exclude<R, Identifier<T>>>;
<E, R, T extends Tag<any, any>>(self: HttpRouter<E, R>, tag: T, service: Service<T>): HttpRouter<E, Exclude<R, Identifier<T>>>;
}

Signature

declare const provideServiceEffect: {
<T extends Tag<any, any>, R1, E1>(tag: T, effect: Effect<Service<T>, E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, Exclude<R, Identifier<T>> | Exclude<Exclude<R1, Provided>, Identifier<T>>>;
<E, R, T extends Tag<any, any>, R1, E1>(self: HttpRouter<E, R>, tag: T, effect: Effect<Service<T>, E1, R1>): HttpRouter<E | E1, Exclude<R, Identifier<T>> | Exclude<Exclude<R1, Provided>, Identifier<T>>>;
}

transform

Added in v1.0.0 Source

Signature

declare const transform: {
<E, R, R1, E1>(f: (self: Handler<E, R>) => HttpApp<Respondable, E1, R1>): (self: HttpRouter<E, R>) => HttpRouter<E1, Exclude<R1, Provided>>;
<E, R, R1, E1>(self: HttpRouter<E, R>, f: (self: Handler<E, R>) => HttpApp<Respondable, E1, R1>): HttpRouter<E1, Exclude<R1, Provided>>;
}

use

Added in v1.0.0 Source

Signature

declare const use: {
<E, R, R1, E1>(f: (self: Middleware<E, R>) => Default<E1, R1>): (self: HttpRouter<E, R>) => HttpRouter<E1, Exclude<R1, Provided>>;
<E, R, R1, E1>(self: HttpRouter<E, R>, f: (self: Middleware<E, R>) => Default<E1, R1>): HttpRouter<E1, Exclude<R1, Provided>>;
}

Constructors

empty

Added in v1.0.0 Source

Signature

declare const empty: HttpRouter

fromIterable

Added in v1.0.0 Source

Signature

declare const fromIterable: <R extends Route<any, any>>(routes: Iterable<R>) => HttpRouter<R extends Route<infer E, infer _> ? E : never, R extends Route<infer _, infer Env> ? Env : never>

makeRoute

Added in v1.0.0 Source

Signature

declare const makeRoute: <E, R>(method: Method.HttpMethod | "*", path: PathInput, handler: Route.Handler<E, R>, options?: {
readonly prefix?: string;
readonly uninterruptible?: boolean;
}) => Route<E, HttpRouter.ExcludeProvided<R>>

Models

HttpRouter interface

Added in v1.0.0 Source

Signature

interface HttpRouter<E = never, R = never> extends Default<E | Error.RouteNotFound, Exclude<R, RouteContext>>, Inspectable {
readonly [TypeId]: typeof TypeId;
readonly mounts: Chunk<readonly [string, Default<E, R>, {
readonly includePrefix?: boolean;
} | undefined]>;
readonly routes: Chunk<Route<E, R>>;
}

PathInput type

Added in v1.0.0 Source

Signature

type PathInput = `/${string}` | "*"

Route interface

Added in v1.0.0 Source

Signature

interface Route<E = never, R = never> extends Inspectable {
readonly [RouteTypeId]: typeof RouteTypeId;
readonly handler: Handler<E, R>;
readonly method: HttpMethod | "*";
readonly path: PathInput;
readonly prefix: Option<string>;
readonly uninterruptible: boolean;
}

RouteContext interface

Added in v1.0.0 Source

Signature

interface RouteContext {
readonly [RouteContextTypeId]: typeof RouteContextTypeId;
readonly params: Readonly<Record<string, string | undefined>>;
readonly route: Route<unknown, unknown>;
}

Other

HttpRouter

Added in v1.0.0 Source

Route

Added in v1.0.0 Source

Route Context

params

Added in v1.0.0 Source

Signature

declare const params: Effect.Effect<Readonly<Record<string, string | undefined>>, never, RouteContext>

RouteContext

Added in v1.0.0 Source

Signature

declare const RouteContext: Tag<RouteContext, RouteContext>

schemaJson

Added in v1.0.0 Source

Signature

declare const schemaJson: <R, I extends Partial<{
readonly body: any;
readonly cookies: Readonly<Record<string, string | undefined>>;
readonly headers: Readonly<Record<string, string | undefined>>;
readonly method: Method.HttpMethod;
readonly pathParams: Readonly<Record<string, string | undefined>>;
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>;
readonly url: string;
}>, A>(schema: Schema.Schema<A, I, R>, options?: ParseOptions) => Effect.Effect<A, Error.RequestError | ParseResult.ParseError, RouteContext | R | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams>

schemaNoBody

Added in v1.0.0 Source

Signature

declare const schemaNoBody: <R, I extends Partial<{
readonly cookies: Readonly<Record<string, string | undefined>>;
readonly headers: Readonly<Record<string, string | undefined>>;
readonly method: Method.HttpMethod;
readonly pathParams: Readonly<Record<string, string | undefined>>;
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>;
readonly url: string;
}>, A>(schema: Schema.Schema<A, I, R>, options?: ParseOptions) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams>

schemaParams

Added in v1.0.0 Source

Signature

declare const schemaParams: <A, I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext | ServerRequest.ParsedSearchParams>

Signature

declare const schemaPathParams: <A, I extends Readonly<Record<string, string | undefined>>, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext>

Router Config

Signature

declare const currentRouterConfig: FiberRef<Partial<RouterConfig>>

Signature

declare const setRouterConfig: (config: Partial<RouterConfig>) => Layer.Layer<never>

Signature

declare const withRouterConfig: {
(config: RouterConfig): <A, E, R>(effect: Effect<A, E, R>) => Effect<A, E, R>;
<A, E, R>(effect: Effect<A, E, R>, config: RouterConfig): Effect<A, E, R>;
}

Routing

all

Added in v1.0.0 Source

Signature

declare const all: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

del

Added in v1.0.0 Source

Signature

declare const del: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

get

Added in v1.0.0 Source

Signature

declare const get: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

mount

Added in v1.0.0 Source

Signature

declare const mount: {
<R1, E1>(path: `/${string}`, that: HttpRouter<E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R1 | R>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: `/${string}`, that: HttpRouter<E1, R1>): HttpRouter<E | E1, R | R1>;
}

mountApp

Added in v1.0.0 Source

Signature

declare const mountApp: {
<R1, E1>(path: `/${string}`, that: Default<E1, R1>, options?: {
readonly includePrefix?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, Exclude<R1, Provided> | Exclude<R, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: `/${string}`, that: Default<E1, R1>, options?: {
readonly includePrefix?: boolean;
}): HttpRouter<E | E1, Exclude<R, Provided> | Exclude<R1, Provided>>;
}

options

Added in v1.0.0 Source

Signature

declare const options: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

patch

Added in v1.0.0 Source

Signature

declare const patch: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

post

Added in v1.0.0 Source

Signature

declare const post: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

put

Added in v1.0.0 Source

Signature

declare const put: {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Provided>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Provided>>;
}

route

Added in v1.0.0 Source

Signature

declare const route: (method: Method.HttpMethod | "*") => {
<R1, E1>(path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | Exclude<R1, Scope | HttpServerRequest | RouteContext>>;
<E, R, E1, R1>(self: HttpRouter<E, R>, path: PathInput, handler: Handler<E1, R1>, options?: {
readonly uninterruptible?: boolean;
}): HttpRouter<E | E1, R | Exclude<R1, Scope | HttpServerRequest | RouteContext>>;
}

Tags

Default

Added in v1.0.0 Source

Signature

declare class Default extends any {
constructor(_: never);
}

Tag

Added in v1.0.0 Source

Signature

declare const Tag: <Name extends string>(id: Name) => <Self, R = never, E = unknown>() => HttpRouter.TagClass<Self, Name, E, R | HttpRouter.DefaultServices>

Type Ids

Signature

declare const RouteContextTypeId: unique symbol

RouteContextTypeId type

Added in v1.0.0 Source

Signature

type RouteContextTypeId = typeof RouteContextTypeId

RouteTypeId

Added in v1.0.0 Source

Signature

declare const RouteTypeId: unique symbol

RouteTypeId type

Added in v1.0.0 Source

Signature

type RouteTypeId = typeof RouteTypeId

TypeId

Added in v1.0.0 Source

Signature

declare const TypeId: unique symbol

TypeId type

Added in v1.0.0 Source

Signature

type TypeId = typeof TypeId

Utils

prefixPath

Added in v1.0.0 Source

Signature

declare const prefixPath: {
(prefix: string): (self: string) => string;
(self: string, prefix: string): string;
}

toHttpApp

Added in v1.0.0 Source

Signature

declare const toHttpApp: <E, R>(self: HttpRouter<E, R>) => Effect.Effect<App.Default<E | Error.RouteNotFound, R>>