Class: abstract
Route<Options>
Since
1.0.0
Examples
// hello.get.ts
import { Route } from '@sapphire/plugin-api';
export class MyRoute extends Route {
public run(request: Route.Request, response: Route.Response) {
return response.json({ message: 'Hello, World!' });
}
}
$ curl http://localhost:4000/hello
{"message":"Hello, World!"}
// echo.post.ts
import { Route } from '@sapphire/plugin-api';
export class MyRoute extends Route {
public run(request: Route.Request, response: Route.Response) {
return response.json(request.params);
}
}
$ curl -X POST -H "Content-Type: application/json" -d '{"hello":"world"}' http://localhost:4000/echo
{"hello":"world"}
Extends
Piece
<Options
,"routes"
>
Type Parameters
Type Parameter | Default type |
---|---|
Options extends Options | Options |
Constructors
new Route()
new Route<
Options
>(context
:LoaderContext
,options
:Options
):Route
<Options
>
Parameters
Parameter | Type |
---|---|
context | LoaderContext |
options | Options |
Returns
Route
<Options
>
Overrides
Piece<Options, 'routes'>.constructor
Defined in
projects/plugins/packages/api/src/lib/structures/Route.ts:61
Properties
maximumBodyLength
readonly
maximumBodyLength:number
(RFC 7230 3.3.2) The maximum decimal number of octets.
Defined in
projects/plugins/packages/api/src/lib/structures/Route.ts:49
methods
readonly
methods:ReadonlySet
<"GET"
|"HEAD"
|"POST"
|"PUT"
|"DELETE"
|"CONNECT"
|"OPTIONS"
|"TRACE"
|"PATCH"
|"ACL"
|"BIND"
|"CHECKOUT"
|"COPY"
|"LINK"
|"LOCK"
|"M-SEARCH"
|"MERGE"
|"MKACTIVITY"
|"MKCALENDAR"
|"MKCOL"
|"MOVE"
|"NOTIFY"
|"PROPFIND"
|"PROPPATCH"
|"PURGE"
|"QUERY"
|"REBIND"
|"REPORT"
|"SEARCH"
|"SOURCE"
|"SUBSCRIBE"
|"UNBIND"
|"UNLINK"
|"UNLOCK"
|"UNSUBSCRIBE"
>
The methods this route accepts.
Defined in
projects/plugins/packages/api/src/lib/structures/Route.ts:59
path
readonly
path: readonlystring
[]
The path this route represents.
Defined in
projects/plugins/packages/api/src/lib/structures/Route.ts:54
Methods
run()
abstract
run(request
:ApiRequest
,response
:Response
):unknown
Parameters
Parameter | Type |
---|---|
request | ApiRequest |
response | Response |
Returns
unknown
Defined in
projects/plugins/packages/api/src/lib/structures/Route.ts:89