HttpRouter.ts overview
Since v1.0.0
Exports Grouped by Category
combinators
append
Signature
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>>
}
Since v1.0.0
catchAll
Signature
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>>
}
Since v1.0.0
catchAllCause
Signature
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>>
}
Since v1.0.0
catchTag
Signature
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>>
}
Since v1.0.0
catchTags
Signature
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]
>
>
}
Since v1.0.0
concat
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>
}
Since v1.0.0
concatAll
Signature
declare const concatAll: <Routers extends ReadonlyArray<HttpRouter<unknown, unknown>>>(
...routers: Routers
) => [Routers[number]] extends [HttpRouter<infer E, infer R>] ? HttpRouter<E, R> : never
Since v1.0.0
prefixAll
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>
}
Since v1.0.0
provideService
Signature
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>>>
}
Since v1.0.0
provideServiceEffect
Signature
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>>
>
}
Since v1.0.0
transform
Signature
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>>
}
Since v1.0.0
use
Signature
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>>
}
Since v1.0.0
constructors
empty
Signature
declare const empty: HttpRouter<never, never>
Since v1.0.0
fromIterable
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>
Since v1.0.0
makeRoute
Signature
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>>
Since 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
]
>
}
Since v1.0.0
PathInput (type alias)
Signature
type PathInput = `/${string}` | "*"
Since 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
}
Since v1.0.0
RouteContext (interface)
Signature
export interface RouteContext {
readonly [RouteContextTypeId]: RouteContextTypeId
readonly params: Readonly<Record<string, string | undefined>>
readonly route: Route<unknown, unknown>
}
Since v1.0.0
route context
RouteContext
Signature
declare const RouteContext: Context.Tag<RouteContext, RouteContext>
Since v1.0.0
params
Signature
declare const params: Effect.Effect<Readonly<Record<string, string | undefined>>, never, RouteContext>
Since v1.0.0
schemaJson
Signature
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
>
Since v1.0.0
schemaNoBody
Signature
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
>
Since v1.0.0
schemaParams
Signature
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>
Since v1.0.0
schemaPathParams
Signature
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>
Since v1.0.0
router config
currentRouterConfig
Signature
declare const currentRouterConfig: FiberRef<Partial<RouterConfig>>
Since v1.0.0
setRouterConfig
Signature
declare const setRouterConfig: (config: Partial<RouterConfig>) => Layer.Layer<never>
Since v1.0.0
withRouterConfig
Signature
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>
}
Since v1.0.0
routing
all
Signature
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>>
}
Since v1.0.0
del
Signature
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>>
}
Since v1.0.0
get
Signature
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>>
}
Since v1.0.0
head
Signature
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>>
}
Since v1.0.0
mount
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>
}
Since v1.0.0
mountApp
Signature
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>>
}
Since v1.0.0
options
Signature
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>>
}
Since v1.0.0
patch
Signature
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>>
}
Since v1.0.0
post
Signature
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>>
}
Since v1.0.0
put
Signature
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>>
}
Since v1.0.0
route
Signature
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>>
}
Since v1.0.0
tags
Default (class)
Signature
declare class Default
Since v1.0.0
Tag
Signature
declare const Tag: <const Name extends string>(
id: Name
) => <Self, R = never, E = unknown>() => HttpRouter.TagClass<Self, Name, E, R | HttpRouter.DefaultServices>
Since v1.0.0
type ids
RouteContextTypeId
Signature
declare const RouteContextTypeId: unique symbol
Since v1.0.0
RouteContextTypeId (type alias)
Signature
type RouteContextTypeId = typeof RouteContextTypeId
Since v1.0.0
RouteTypeId
Signature
declare const RouteTypeId: unique symbol
Since v1.0.0
RouteTypeId (type alias)
Signature
type RouteTypeId = typeof RouteTypeId
Since v1.0.0
TypeId
Signature
declare const TypeId: unique symbol
Since v1.0.0
TypeId (type alias)
Signature
type TypeId = typeof TypeId
Since v1.0.0
utils
HttpRouter (namespace)
Since 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>
}
Since 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, Exclude<XR, Scope.Scope>>
readonly unwrap: <XA, XE, XR>(f: (router: HttpRouter<E, R>) => Layer.Layer<XA, XE, XR>) => Layer.Layer<XA, XE, XR>
readonly serve: <E = never, R = never>(
middleware?: Middleware.HttpMiddleware.Applied<App.Default, E, R>
) => Layer.Layer<never, never, HttpServer.HttpServer | Exclude<R, ServerRequest.HttpServerRequest | Scope.Scope>>
}
Since v1.0.0
Provided (type alias)
Signature
type Provided = RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope
Since v1.0.0
ExcludeProvided (type alias)
Signature
type any = Exclude<A, Provided>
Since v1.0.0
DefaultServices (type alias)
Signature
type DefaultServices = Platform.HttpPlatform | Etag.Generator | FileSystem | Path
Since v1.0.0
Route (namespace)
Since v1.0.0
Handler (type alias)
Signature
type Effect.Effect<A, E, ServerRequest.HttpServerRequest | R> = App.HttpApp<
Respondable.Respondable,
E,
R | RouteContext | ServerRequest.ParsedSearchParams
>
Since v1.0.0
Middleware (type alias)
Signature
type Effect.Effect<A, E, ServerRequest.HttpServerRequest | R> = App.HttpApp<
ServerResponse.HttpServerResponse,
E,
R | RouteContext | ServerRequest.ParsedSearchParams
>
Since v1.0.0
prefixPath
Signature
declare const prefixPath: { (prefix: string): (self: string) => string; (self: string, prefix: string): string }
Since v1.0.0