nextjs-koa-api / Router
Name | Type |
---|---|
StateT |
DefaultState |
ContextT |
DefaultContext |
- all
- allowedMethods
- del
- delete
- get
- head
- link
- match
- middleware
- options
- param
- patch
- post
- prefix
- put
- redirect
- register
- route
- routes
- unlink
- url
- use
- url
• new Router<StateT
, ContextT
>(opt?
)
Create a new router.
Name | Type |
---|---|
StateT |
DefaultState |
ContextT |
DefaultContext |
Name | Type |
---|---|
opt? |
RouterOptions |
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:167
• methods: string
[]
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:160
• opts: RouterOptions
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:159
• params: object
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:161
• stack: Layer
[]
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:162
▸ all<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
Register route with all methods.
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:320
▸ 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.
Name | Type |
---|---|
options? |
RouterAllowedMethodsOptions |
Middleware
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:345
▸ del<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
Alias for router.delete()
because delete is a reserved word
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:268
▸ delete<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP delete method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:255
▸ get<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP get method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:190
▸ head<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP head method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:281
▸ link<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP link method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:229
▸ match(path
, method
): RoutesMatch
Match given path
and return corresponding routes.
Name | Type |
---|---|
path |
string |
method |
string |
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:395
▸ middleware(): Middleware
<StateT
, ContextT
>
Returns router middleware which dispatches a route matching the request.
Middleware
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:338
▸ options<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP options method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:294
▸ param(param
, middleware
): Router
<StateT
, ContextT
>
Run middleware for named route parameters. Useful for auto-loading or validation.
Name | Type |
---|---|
param |
string |
middleware |
ParamMiddleware |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:400
▸ patch<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP patch method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:307
▸ post<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP post method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:203
▸ prefix(prefix
): Router
<StateT
, ContextT
>
Set the path prefix for a Router instance that was already initialized.
Name | Type |
---|---|
prefix |
string |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:328
▸ put<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP put method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:216
▸ 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.
Name | Type |
---|---|
source |
string |
destination |
string |
code? |
number |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:354
▸ register(path
, methods
, middleware
, opts?
): Layer
Create and register a route.
Name | Type |
---|---|
path |
string | RegExp |
methods |
string [] |
middleware |
Middleware <StateT , ContextT > | Middleware <StateT , ContextT >[] |
opts? |
LayerOptions |
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:359
▸ route(name
): boolean
| Layer
Lookup route with given name
.
Name | Type |
---|---|
name |
string |
boolean
| Layer
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:369
▸ routes(): Middleware
<StateT
, ContextT
>
Returns router middleware which dispatches a route matching the request.
Middleware
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:333
▸ unlink<T
, U
>(name
, path
, ...middleware
): Router
<StateT
, ContextT
>
HTTP unlink method
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
name |
string |
path |
string | RegExp |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
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
>
Name | Type |
---|---|
T |
{} |
U |
{} |
Name | Type |
---|---|
path |
string | RegExp | (string | RegExp )[] |
...middleware |
Middleware <StateT & T , ContextT & U >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:242
▸ 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"
Name | Type |
---|---|
name |
string |
params? |
any |
options? |
UrlOptionsQuery |
string
| Error
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:390
▸ 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.
Name | Type |
---|---|
...middleware |
Middleware <StateT , ContextT >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:176
▸ use(path
, ...middleware
): Router
<StateT
, ContextT
>
Name | Type |
---|---|
path |
string | RegExp | string [] |
...middleware |
Middleware <StateT , ContextT >[] |
Router
<StateT
, ContextT
>
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:177
▸ Static
url(path
, params
): string
Generate URL from url pattern and given params
.
Name | Type |
---|---|
path |
string | RegExp |
params |
object |
string
node_modules/.pnpm/@types+koa__router@8.0.11/node_modules/@types/koa__router/index.d.ts:405