Skip to content

Files

Latest commit

45c6d4c · May 14, 2022

History

History
1021 lines (620 loc) · 29.7 KB

Router.md

File metadata and controls

1021 lines (620 loc) · 29.7 KB

nextjs-koa-api / Router

Class: Router<StateT, ContextT>

Type parameters

Name Type
StateT DefaultState
ContextT DefaultContext

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Router<StateT, ContextT>(opt?)

Create a new router.

Type parameters

Name Type
StateT DefaultState
ContextT DefaultContext

Parameters

Name Type
opt? RouterOptions

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:167

Properties

methods

methods: string[]

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:160


opts

opts: RouterOptions

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:159


params

params: object

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:161


stack

stack: Layer[]

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:162

Methods

all

all<T, U>(name, path, ...middleware): Router<StateT, ContextT>

Register route with all methods.

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:315

all<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:320


allowedMethods

allowedMethods(options?): Middleware<StateT, ContextT>

Returns separate middleware for responding to OPTIONS requests with an Allow header containing the allowed methods, as well as responding with 405 Method Not Allowed and 501 Not Implemented as appropriate.

Parameters

Name Type
options? RouterAllowedMethodsOptions

Returns

Middleware<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:345


del

del<T, U>(name, path, ...middleware): Router<StateT, ContextT>

Alias for router.delete() because delete is a reserved word

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:263

del<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:268


delete

delete<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP delete method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:250

delete<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:255


get

get<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP get method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:185

get<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:190


head

head<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP head method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:276

head<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:281


link

link<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP link method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:224

link<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:229


match

match(path, method): RoutesMatch

Match given path and return corresponding routes.

Parameters

Name Type
path string
method string

Returns

RoutesMatch

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:395


middleware

middleware(): Middleware<StateT, ContextT>

Returns router middleware which dispatches a route matching the request.

Returns

Middleware<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:338


options

options<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP options method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:289

options<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:294


param

param(param, middleware): Router<StateT, ContextT>

Run middleware for named route parameters. Useful for auto-loading or validation.

Parameters

Name Type
param string
middleware ParamMiddleware

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:400


patch

patch<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP patch method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:302

patch<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:307


post

post<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP post method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:198

post<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:203


prefix

prefix(prefix): Router<StateT, ContextT>

Set the path prefix for a Router instance that was already initialized.

Parameters

Name Type
prefix string

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:328


put

put<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP put method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:211

put<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:216


redirect

redirect(source, destination, code?): Router<StateT, ContextT>

Redirect source to destination URL with optional 30x status code.

Both source and destination can be route names.

Parameters

Name Type
source string
destination string
code? number

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:354


register

register(path, methods, middleware, opts?): Layer

Create and register a route.

Parameters

Name Type
path string | RegExp
methods string[]
middleware Middleware<StateT, ContextT> | Middleware<StateT, ContextT>[]
opts? LayerOptions

Returns

Layer

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:359


route

route(name): boolean | Layer

Lookup route with given name.

Parameters

Name Type
name string

Returns

boolean | Layer

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:369


routes

routes(): Middleware<StateT, ContextT>

Returns router middleware which dispatches a route matching the request.

Returns

Middleware<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:333


unlink

unlink<T, U>(name, path, ...middleware): Router<StateT, ContextT>

HTTP unlink method

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
name string
path string | RegExp
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:237

unlink<T, U>(path, ...middleware): Router<StateT, ContextT>

Type parameters

Name Type
T {}
U {}

Parameters

Name Type
path string | RegExp | (string | RegExp)[]
...middleware Middleware<StateT & T, ContextT & U>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:242


url

url(name, params?, options?): string | Error

Generate URL for route. Takes either map of named params or series of arguments (for regular expression routes)

router = new Router(); router.get('user', "/users/:id", ...

router.url('user', { id: 3 }); // => "/users/3"

Query can be generated from third argument:

router.url('user', { id: 3 }, { query: { limit: 1 } }); // => "/users/3?limit=1"

router.url('user', { id: 3 }, { query: "limit=1" }); // => "/users/3?limit=1"

Parameters

Name Type
name string
params? any
options? UrlOptionsQuery

Returns

string | Error

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:390


use

use(...middleware): Router<StateT, ContextT>

Use given middleware.

Middleware run in the order they are defined by .use(). They are invoked sequentially, requests start at the first middleware and work their way "down" the middleware stack.

Parameters

Name Type
...middleware Middleware<StateT, ContextT>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:176

use(path, ...middleware): Router<StateT, ContextT>

Parameters

Name Type
path string | RegExp | string[]
...middleware Middleware<StateT, ContextT>[]

Returns

Router<StateT, ContextT>

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:177


url

Static url(path, params): string

Generate URL from url pattern and given params.

Parameters

Name Type
path string | RegExp
params object

Returns

string

Defined in

node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:405