HttpRouter overview
Added in v1.0.0
Table of contents
combinators
append
Signature
export declare const append: {
<R1, E1>(
route: Route<E1, R1>
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(self: HttpRouter<E, R>, route: Route<E1, R1>): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
catchAll
Signature
export declare const catchAll: {
<E, E2, R2>(
f: (e: E) => Route.Handler<E2, R2>
): <R>(self: HttpRouter<E, R>) => HttpRouter<E2, R | HttpRouter.ExcludeProvided<R2>>
<E, R, E2, R2>(
self: HttpRouter<E, R>,
f: (e: E) => Route.Handler<E2, R2>
): HttpRouter<E2, R | HttpRouter.ExcludeProvided<R2>>
}
Added in v1.0.0
catchAllCause
Signature
export declare const catchAllCause: {
<E, E2, R2>(
f: (e: Cause.Cause<E>) => Route.Handler<E2, R2>
): <R>(self: HttpRouter<E, R>) => HttpRouter<E2, R | HttpRouter.ExcludeProvided<R2>>
<E, R, E2, R2>(
self: HttpRouter<E, R>,
f: (e: Cause.Cause<E>) => Route.Handler<E2, R2>
): HttpRouter<E2, R | HttpRouter.ExcludeProvided<R2>>
}
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 }>) => Route.Handler<E1, R1>
): <R>(self: HttpRouter<E, R>) => HttpRouter<E1 | Exclude<E, { _tag: K }>, R | HttpRouter.ExcludeProvided<R1>>
<E, R, K extends E extends { _tag: string } ? E["_tag"] : never, E1, R1>(
self: HttpRouter<E, R>,
k: K,
f: (e: Extract<E, { _tag: K }>) => Route.Handler<E1, R1>
): HttpRouter<E1 | Exclude<E, { _tag: K }>, R | HttpRouter.ExcludeProvided<R1>>
}
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 }>) => Route.Handler<any, any>) | undefined }
: {}
>(
cases: Cases
): <R>(
self: HttpRouter<E, R>
) => HttpRouter<
| 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
| HttpRouter.ExcludeProvided<
{
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
}[keyof Cases]
>
>
<
R,
E,
Cases extends E extends { _tag: string }
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | undefined }
: {}
>(
self: HttpRouter<E, R>,
cases: Cases
): HttpRouter<
| 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
| HttpRouter.ExcludeProvided<
{
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
}[keyof Cases]
>
>
}
Added in v1.0.0
concat
Signature
export 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>
}
Added in v1.0.0
concatAll
Signature
export declare const concatAll: <Routers extends ReadonlyArray<HttpRouter<unknown, unknown>>>(
...routers: Routers
) => [Routers[number]] extends [HttpRouter<infer E, infer R>] ? HttpRouter<E, R> : never
Added in v1.0.0
prefixAll
Signature
export 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>
}
Added in v1.0.0
provideService
Signature
export declare const provideService: {
<T extends Context.Tag<any, any>>(
tag: T,
service: Context.Tag.Service<T>
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E, Exclude<R, Context.Tag.Identifier<T>>>
<E, R, T extends Context.Tag<any, any>>(
self: HttpRouter<E, R>,
tag: T,
service: Context.Tag.Service<T>
): HttpRouter<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>
): <E, R>(
self: HttpRouter<E, R>
) => HttpRouter<
E1 | E,
Exclude<R, Context.Tag.Identifier<T>> | Exclude<HttpRouter.ExcludeProvided<R1>, Context.Tag.Identifier<T>>
>
<E, R, T extends Context.Tag<any, any>, R1, E1>(
self: HttpRouter<E, R>,
tag: T,
effect: Effect.Effect<Context.Tag.Service<T>, E1, R1>
): HttpRouter<
E | E1,
Exclude<R, Context.Tag.Identifier<T>> | Exclude<HttpRouter.ExcludeProvided<R1>, Context.Tag.Identifier<T>>
>
}
Added in v1.0.0
transform
Signature
export declare const transform: {
<E, R, R1, E1>(
f: (self: Route.Handler<E, R>) => App.HttpApp<Respondable.Respondable, E1, R1>
): (self: HttpRouter<E, R>) => HttpRouter<E1, HttpRouter.ExcludeProvided<R1>>
<E, R, R1, E1>(
self: HttpRouter<E, R>,
f: (self: Route.Handler<E, R>) => App.HttpApp<Respondable.Respondable, E1, R1>
): HttpRouter<E1, HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
use
Signature
export declare const use: {
<E, R, R1, E1>(
f: (self: Route.Middleware<E, R>) => App.Default<E1, R1>
): (self: HttpRouter<E, R>) => HttpRouter<E1, HttpRouter.ExcludeProvided<R1>>
<E, R, R1, E1>(
self: HttpRouter<E, R>,
f: (self: Route.Middleware<E, R>) => App.Default<E1, R1>
): HttpRouter<E1, HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
constructors
empty
Signature
export declare const empty: HttpRouter<never, never>
Added in v1.0.0
fromIterable
Signature
export 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>
Added in v1.0.0
makeRoute
Signature
export declare const makeRoute: <E, R>(
method: Method.HttpMethod,
path: PathInput,
handler: Route.Handler<E, R>,
options?: { readonly prefix?: string | undefined; readonly uninterruptible?: boolean | undefined } | undefined
) => Route<E, HttpRouter.ExcludeProvided<R>>
Added in v1.0.0
models
HttpRouter (interface)
Signature
export interface HttpRouter<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
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.HttpMethod | "*"
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>
}
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.HttpMethod
readonly url: string
readonly cookies: Readonly<Record<string, string | undefined>>
readonly headers: Readonly<Record<string, string | undefined>>
readonly pathParams: Readonly<Record<string, string | undefined>>
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
readonly body: any
}>,
A
>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<
A,
Error.RequestError | ParseResult.ParseError,
RouteContext | R | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams
>
Added in v1.0.0
schemaNoBody
Signature
export declare const schemaNoBody: <
R,
I extends Partial<{
readonly method: Method.HttpMethod
readonly url: string
readonly cookies: Readonly<Record<string, string | undefined>>
readonly headers: Readonly<Record<string, string | undefined>>
readonly pathParams: Readonly<Record<string, string | undefined>>
readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
}>,
A
>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<
A,
ParseResult.ParseError,
R | RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams
>
Added in v1.0.0
schemaParams
Signature
export declare const schemaParams: <
A,
I extends Readonly<Record<string, string | ReadonlyArray<string> | undefined>>,
R
>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext | ServerRequest.ParsedSearchParams>
Added in v1.0.0
schemaPathParams
Signature
export declare const schemaPathParams: <A, I extends Readonly<Record<string, string | undefined>>, R>(
schema: Schema.Schema<A, I, R>,
options?: ParseOptions | undefined
) => Effect.Effect<A, ParseResult.ParseError, R | RouteContext>
Added in v1.0.0
router config
currentRouterConfig
Signature
export declare const currentRouterConfig: FiberRef<Partial<RouterConfig>>
Added in v1.0.0
setRouterConfig
Signature
export declare const setRouterConfig: (config: Partial<RouterConfig>) => Layer.Layer<never>
Added in v1.0.0
withRouterConfig
Signature
export declare const withRouterConfig: {
(config: Partial<RouterConfig>): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
<A, E, R>(effect: Effect.Effect<A, E, R>, config: Partial<RouterConfig>): Effect.Effect<A, E, R>
}
Added in v1.0.0
routing
all
Signature
export declare const all: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
del
Signature
export declare const del: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
get
Signature
export declare const get: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
head
Signature
export declare const head: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
mount
Signature
export 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>
}
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
): <E, R>(
self: HttpRouter<E, R>
) => HttpRouter<E1 | E, HttpRouter.ExcludeProvided<R1> | HttpRouter.ExcludeProvided<R>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: `/${string}`,
that: App.Default<E1, R1>,
options?: { readonly includePrefix?: boolean | undefined } | undefined
): HttpRouter<E | E1, HttpRouter.ExcludeProvided<R> | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
options
Signature
export declare const options: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
patch
Signature
export declare const patch: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
post
Signature
export declare const post: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
put
Signature
export declare const put: {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>
}
Added in v1.0.0
route
Signature
export declare const route: (method: Method.HttpMethod | "*") => {
<R1, E1>(
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): <E, R>(
self: HttpRouter<E, R>
) => HttpRouter<E1 | E, R | Exclude<R1, ServerRequest.HttpServerRequest | RouteContext | Scope.Scope>>
<E, R, E1, R1>(
self: HttpRouter<E, R>,
path: PathInput,
handler: Route.Handler<E1, R1>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
): HttpRouter<E | E1, R | Exclude<R1, ServerRequest.HttpServerRequest | RouteContext | Scope.Scope>>
}
Added in v1.0.0
tags
Default (class)
Signature
export declare class Default
Added in v1.0.0
Tag
Signature
export declare const Tag: <const Name extends string>(
id: Name
) => <Self, R = never, E = unknown>() => HttpRouter.TagClass<Self, Name, E, R | HttpRouter.DefaultServices>
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
HttpRouter (namespace)
Added in v1.0.0
Service (interface)
Signature
export interface Service<E, R> {
readonly router: Effect.Effect<HttpRouter<E, R>>
readonly addRoute: (route: Route<E, R>) => Effect.Effect<void>
readonly all: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly get: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly post: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly put: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly patch: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly del: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly head: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly options: (
path: PathInput,
handler: Route.Handler<E, R | Provided>,
options?: { readonly uninterruptible?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly mount: (path: `/${string}`, router: HttpRouter<E, R>) => Effect.Effect<void>
readonly mountApp: (
path: `/${string}`,
router: App.Default<E, R>,
options?: { readonly includePrefix?: boolean | undefined } | undefined
) => Effect.Effect<void>
readonly concat: (router: HttpRouter<E, R>) => Effect.Effect<void>
}
Added in v1.0.0
TagClass (interface)
Signature
export interface TagClass<Self, Name extends string, E, R> extends Context.Tag<Self, Service<E, R>> {
new (_: never): Context.TagClassShape<Name, Service<E, R>>
readonly Live: Layer.Layer<Self>
readonly router: Effect.Effect<HttpRouter<E, R>, never, Self>
readonly use: <XA, XE, XR>(f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>) => Layer.Layer<never, XE, XR>
readonly useScoped: <XA, XE, XR>(
f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>
) => Layer.Layer<never, XE, Exclude<XR, Scope.Scope>>
readonly unwrap: <XA, XE, XR>(f: (router: HttpRouter<E, R>) => Layer.Layer<XA, XE, XR>) => Layer.Layer<XA, XE, XR>
}
Added in v1.0.0
DefaultServices (type alias)
Signature
export type DefaultServices = Platform.HttpPlatform | Etag.Generator | FileSystem | Path
Added in v1.0.0
ExcludeProvided (type alias)
Signature
export type ExcludeProvided<A> = Exclude<A, Provided>
Added in v1.0.0
Provided (type alias)
Signature
export type Provided = RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope
Added in v1.0.0
Route (namespace)
Added in v1.0.0
Handler (type alias)
Signature
export type Handler<E, R> = App.HttpApp<Respondable.Respondable, E, R | RouteContext | ServerRequest.ParsedSearchParams>
Added in v1.0.0
Middleware (type alias)
Signature
export type Middleware<E, R> = App.HttpApp<
ServerResponse.HttpServerResponse,
E,
R | RouteContext | ServerRequest.ParsedSearchParams
>
Added in v1.0.0
prefixPath
Signature
export declare const prefixPath: { (prefix: string): (self: string) => string; (self: string, prefix: string): string }
Added in v1.0.0