Router overview
Added in v1.0.0
Table of contents
combinators
catchAll
Signature
export declare const catchAll: {
<E, E2, R2>(
f: (e: E) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): <R>(self: Router<E, R>) => Router<E2, R | Exclude<R2, any>>
<R, E, E2, R2>(
self: Router<E, R>,
f: (e: E) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): Router<E2, R | Exclude<R2, any>>
}
Added in v1.0.0
catchAllCause
Signature
export declare const catchAllCause: {
<E, E2, R2>(
f: (
e: Cause.Cause<E>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): <R>(self: Router<E, R>) => Router<E2, R | Exclude<R2, any>>
<R, E, E2, R2>(
self: Router<E, R>,
f: (
e: Cause.Cause<E>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): Router<E2, R | Exclude<R2, any>>
}
Added in v1.0.0
catchTag
Signature
export declare const catchTag: {
<K extends E extends { _tag: string } ? E["_tag"] : never, E, E1, R1>(
k: K,
f: (
e: Extract<E, { _tag: K }>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): <R>(self: Router<E, R>) => Router<E1 | Exclude<E, { _tag: K }>, R | Exclude<R1, any>>
<R, E, K extends E extends { _tag: string } ? E["_tag"] : never, E1, R1>(
self: Router<E, R>,
k: K,
f: (
e: Extract<E, { _tag: K }>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
): Router<E1 | Exclude<E, { _tag: K }>, R | Exclude<R1, any>>
}
Added in v1.0.0
catchTags
Signature
export declare const catchTags: {
<
E,
Cases extends E extends { _tag: string }
? {
[K in E["_tag"]]+?:
| ((
error: Extract<E, { _tag: K }>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>)
| undefined
}
: {}
>(
cases: Cases
): <R>(
self: Router<E, R>
) => Router<
| Exclude<E, { _tag: keyof Cases }>
| {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
}[keyof Cases],
| R
| Exclude<
{
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
}[keyof Cases],
any
>
>
<
R,
E,
Cases extends E extends { _tag: string }
? {
[K in E["_tag"]]+?:
| ((
error: Extract<E, { _tag: K }>
) => Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>)
| undefined
}
: {}
>(
self: Router<E, R>,
cases: Cases
): Router<
| Exclude<E, { _tag: keyof Cases }>
| {
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
}[keyof Cases],
| R
| Exclude<
{
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
}[keyof Cases],
any
>
>
}
Added in v1.0.0
concat
Signature
export declare const concat: {
<R1, E1>(that: Router<E1, R1>): <R, E>(self: Router<E, R>) => Router<E1 | E, R1 | R>
<R, E, R1, E1>(self: Router<E, R>, that: Router<E1, R1>): Router<E | E1, R | R1>
}
Added in v1.0.0
prefixAll
Signature
export declare const prefixAll: {
(prefix: PathInput): <R, E>(self: Router<E, R>) => Router<E, R>
<R, E>(self: Router<E, R>, prefix: PathInput): Router<E, R>
}
Added in v1.0.0
provideService
Signature
export declare const provideService: {
<T extends Context.Tag<any, any>>(
tag: T,
service: Context.Tag.Service<T>
): <R, E>(self: Router<E, R>) => Router<E, Exclude<R, Context.Tag.Identifier<T>>>
<R, E, T extends Context.Tag<any, any>>(
self: Router<E, R>,
tag: T,
service: Context.Tag.Service<T>
): Router<E, Exclude<R, Context.Tag.Identifier<T>>>
}
Added in v1.0.0
provideServiceEffect
Signature
export declare const provideServiceEffect: {
<T extends Context.Tag<any, any>, R1, E1>(
tag: T,
effect: Effect.Effect<Context.Tag.Service<T>, E1, R1>
): <R, E>(
self: Router<E, R>
) => Router<E1 | E, Exclude<R, Context.Tag.Identifier<T>> | Exclude<Exclude<R1, any>, Context.Tag.Identifier<T>>>
<R, E, T extends Context.Tag<any, any>, R1, E1>(
self: Router<E, R>,
tag: T,
effect: Effect.Effect<Context.Tag.Service<T>, E1, R1>
): Router<E | E1, Exclude<R, Context.Tag.Identifier<T>> | Exclude<Exclude<R1, any>, Context.Tag.Identifier<T>>>
}
Added in v1.0.0
use
Signature
export declare const use: {
<E, R, R1, E1>(
f: (
self: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
) => App.Default<E1, R1>
): (self: Router<E, R>) => Router<E1, Exclude<R1, any>>
<E, R, R1, E1>(
self: Router<E, R>,
f: (
self: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>
) => App.Default<E1, R1>
): Router<E1, Exclude<R1, any>>
}
Added in v1.0.0
constructors
empty
Signature
export declare const empty: Router<never, never>
Added in v1.0.0
fromIterable
Signature
export declare const fromIterable: <R extends Route<any, any>>(
routes: Iterable<R>
) => Router<R extends Route<infer E, infer _> ? E : never, R extends Route<infer _, infer Env> ? Env : never>
Added in v1.0.0
makeRoute
Signature
export declare const makeRoute: <E, R>(
method: Method.Method,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
prefix?: any,
uninterruptible?: boolean
) => Route<E, Exclude<R, any>>
Added in v1.0.0
models
PathInput (type alias)
Signature
export type PathInput = `/${string}` | "*"
Added in v1.0.0
Route (interface)
Signature
export interface Route<E = never, R = never> extends Inspectable {
readonly [RouteTypeId]: RouteTypeId
readonly method: Method.Method | "*"
readonly path: PathInput
readonly handler: Route.Handler<E, R>
readonly prefix: Option.Option<string>
readonly uninterruptible: boolean
}
Added in v1.0.0
RouteContext (interface)
Signature
export interface RouteContext {
readonly [RouteContextTypeId]: RouteContextTypeId
readonly params: Readonly<Record<string, string | undefined>>
readonly route: Route<unknown, unknown>
readonly searchParams: Readonly<Record<string, string>>
}
Added in v1.0.0
Router (interface)
Signature
export interface Router<E = never, R = never>
extends App.Default<E | Error.RouteNotFound, Exclude<R, RouteContext>>,
Inspectable {
readonly [TypeId]: TypeId
readonly routes: Chunk.Chunk<Route<E, R>>
readonly mounts: Chunk.Chunk<
readonly [
prefix: string,
httpApp: App.Default<E, R>,
options?: { readonly includePrefix?: boolean | undefined } | undefined
]
>
}
Added in v1.0.0
route context
RouteContext
Signature
export declare const RouteContext: Context.Tag<RouteContext, RouteContext>
Added in v1.0.0
params
Signature
export declare const params: Effect.Effect<Readonly<Record<string, string | undefined>>, never, RouteContext>
Added in v1.0.0
schemaJson
Signature
export declare const schemaJson: <
R,
I extends Partial<{
readonly method: Method.Method
readonly url: string
readonly cookies: Readonly<Record<string, string>>
readonly headers: Readonly<Record<string, string>>
readonly pathParams: Readonly<Record<string, string>>
readonly searchParams: Readonly<Record<string, string>>
readonly body: any
}>,
A
>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, any, ServerRequest.ServerRequest | RouteContext | R>
Added in v1.0.0
schemaNoBody
Signature
export declare const schemaNoBody: <
R,
I extends Partial<{
readonly method: Method.Method
readonly url: string
readonly cookies: Readonly<Record<string, string>>
readonly headers: Readonly<Record<string, string>>
readonly pathParams: Readonly<Record<string, string>>
readonly searchParams: Readonly<Record<string, string>>
}>,
A
>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, ServerRequest.ServerRequest | RouteContext | R>
Added in v1.0.0
schemaParams
Signature
export declare const schemaParams: <R, I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R>
Added in v1.0.0
schemaPathParams
Signature
export declare const schemaPathParams: <R, I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R>
Added in v1.0.0
schemaSearchParams
Signature
export declare const schemaSearchParams: <R, I extends Readonly<Record<string, string>>, A>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, RouteContext | R>
Added in v1.0.0
searchParams
Signature
export declare const searchParams: Effect.Effect<Readonly<Record<string, string>>, never, RouteContext>
Added in v1.0.0
routing
all
Signature
export declare const all: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
del
Signature
export declare const del: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
get
Signature
export declare const get: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
head
Signature
export declare const head: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
mount
Signature
export declare const mount: {
<R1, E1>(path: `/${string}`, that: Router<E1, R1>): <R, E>(self: Router<E, R>) => Router<E1 | E, R1 | R>
<R, E, R1, E1>(self: Router<E, R>, path: `/${string}`, that: Router<E1, R1>): Router<E | E1, R | R1>
}
Added in v1.0.0
mountApp
Signature
export declare const mountApp: {
<R1, E1>(
path: `/${string}`,
that: App.Default<E1, R1>,
options?: { readonly includePrefix?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, Exclude<R1, any> | Exclude<R, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: `/${string}`,
that: App.Default<E1, R1>,
options?: { readonly includePrefix?: boolean | undefined } | undefined
): Router<E | E1, Exclude<R, any> | Exclude<R1, any>>
}
Added in v1.0.0
options
Signature
export declare const options: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
patch
Signature
export declare const patch: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
post
Signature
export declare const post: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
put
Signature
export declare const put: {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
route
Signature
export declare const route: (method: Method.Method | "*") => {
<R1, E1>(
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <R, E>(self: Router<E, R>) => Router<E1 | E, R | Exclude<R1, any>>
<R, E, R1, E1>(
self: Router<E, R>,
path: PathInput,
handler: Effect.Effect<ServerResponse.ServerResponse, E, ServerRequest.ServerRequest | RouteContext | R>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): Router<E | E1, R | Exclude<R1, any>>
}
Added in v1.0.0
type ids
RouteContextTypeId
Signature
export declare const RouteContextTypeId: typeof RouteContextTypeId
Added in v1.0.0
RouteContextTypeId (type alias)
Signature
export type RouteContextTypeId = typeof RouteContextTypeId
Added in v1.0.0
RouteTypeId
Signature
export declare const RouteTypeId: typeof RouteTypeId
Added in v1.0.0
RouteTypeId (type alias)
Signature
export type RouteTypeId = typeof RouteTypeId
Added in v1.0.0
TypeId
Signature
export declare const TypeId: typeof TypeId
Added in v1.0.0
TypeId (type alias)
Signature
export type TypeId = typeof TypeId
Added in v1.0.0
utils
Route (namespace)
Added in v1.0.0
Handler (type alias)
Signature
export type Handler<E, R> = Effect.Effect<
ServerResponse.ServerResponse,
E,
R | RouteContext | ServerRequest.ServerRequest
>
Added in v1.0.0
Router (namespace)
Added in v1.0.0
ExcludeProvided (type alias)
Signature
export type ExcludeProvided<A> = Exclude<A, RouteContext | ServerRequest.ServerRequest | Scope.Scope>
Added in v1.0.0