router
Types from PocketBase's Go package router, as JavaScript sees them: you get these objects from $app and the other globals and from hook events, and call their methods by their JS names (Go's FindRecordById is findRecordById). The same package in Go: router.
router.ApiError
ApiError defines the struct for a basic api error response.
| Member | Type | |
|---|---|---|
data |
{ [key: string]: any } |
|
message |
string |
|
status |
number |
|
error() |
(): string |
Error makes it compatible with the error interface. |
rawData() |
(): any |
RawData returns the unformatted error data (could be an internal error, text, etc.) |
is() |
(target: Error): boolean |
Is reports whether the current ApiError wraps the target. |
router.Event
Has everything hook.Event has.
| Member | Type | |
|---|---|---|
response |
http.ResponseWriter |
|
request? |
http.Request |
|
written() |
(): boolean |
Written reports whether the current response has already been written. |
status() |
(): number |
Status reports the status code of the current response. |
flush() |
(): void |
Flush flushes buffered data to the current response. |
isTLS() |
(): boolean |
IsTLS reports whether the connection on which the request was received is TLS. |
setCookie() |
(cookie: http.Cookie): void |
SetCookie is an alias for http.setCookie. |
remoteIP() |
(): string |
RemoteIP returns the IP address of the client that sent the request. |
findUploadedFiles() |
(key: string): Array<(filesystem.File | undefined)> |
FindUploadedFiles extracts all form files of "key" from a http request and returns a slice with filesystem.File instances (if any). |
get() |
(key: string): any |
Get retrieves single value from the current event data store. |
getAll() |
(): { [key: string]: any } |
GetAll returns a copy of the current event data store. |
set() |
(key: string, value: any): void |
Set saves single value into the current event data store. |
setAll() |
(m: { [key: string]: any }): void |
SetAll saves all items from m into the current event data store. |
string() |
(status: number, data: string): void |
String writes a plain string response. |
html() |
(status: number, data: string): void |
HTML writes an HTML response. |
json() |
(status: number, data: any): void |
JSON writes a JSON response. |
xml() |
(status: number, data: any): void |
XML writes an XML response. It automatically prepends the generic xml.header string to the response. |
stream() |
(status: number, contentType: string, reader: io.Reader): void |
Stream streams the specified reader into the response. |
blob() |
(status: number, contentType: string, b: string|Array<number>): void |
Blob writes a blob (bytes slice) response. |
fileFS() |
(fsys: fs.FS, filename: string): void |
FileFS serves the specified filename from fsys. |
noContent() |
(status: number): void |
NoContent writes a response with no body (ex. 204). |
redirect() |
(status: number, url: string): void |
Redirect writes a redirect response to the specified url. The status code must be in between 300 – 399 range. |
error() |
(status: number, message: string, errData: any): (ApiError) |
|
badRequestError() |
(message: string, errData: any): (ApiError) |
|
notFoundError() |
(message: string, errData: any): (ApiError) |
|
forbiddenError() |
(message: string, errData: any): (ApiError) |
|
unauthorizedError() |
(message: string, errData: any): (ApiError) |
|
tooManyRequestsError() |
(message: string, errData: any): (ApiError) |
|
internalServerError() |
(message: string, errData: any): (ApiError) |
|
bindBody() |
(dst: any): void |
BindBody unmarshal the request body into the provided dst. |
router.Router
Has everything _t086<T> has.
| Member | Type | |
|---|---|---|
buildMux() |
(): http.Handler |
BuildMux constructs a new mux http.handler instance from the current router configurations. |
router.RouterGroup
RouterGroup represents a collection of routes and other sub groups that share common pattern prefix and middlewares.
| Member | Type | |
|---|---|---|
prefix |
string |
|
middlewares |
Array<(hook.Handler<T> | undefined)> |
|
group() |
(prefix: string): (RouterGroup<T>) |
Group creates and register a new child Group into the current one with the specified prefix. |
bindFunc() |
(...middlewareFuncs: ((e: T) => void)[]): (RouterGroup<T>) |
BindFunc registers one or multiple middleware functions to the current group. |
bind() |
(...middlewares: (hook.Handler<T> | undefined)[]): (RouterGroup<T>) |
Bind registers one or multiple middleware handlers to the current group. |
unbind() |
(...middlewareIds: string[]): (RouterGroup<T>) |
Unbind removes one or more middlewares with the specified id(s) from the current group and its children (if any). |
route() |
(method: string, path: string, action: (e: T) => void): (Route<T>) |
Route registers a single route into the current group. |
any() |
(path: string, action: (e: T) => void): (Route<T>) |
Any is a shorthand for RouterGroup.addRoute with "" as route method (aka. matches any method). |
get() |
(path: string, action: (e: T) => void): (Route<T>) |
GET is a shorthand for RouterGroup.addRoute with GET as route method. |
search() |
(path: string, action: (e: T) => void): (Route<T>) |
SEARCH is a shorthand for RouterGroup.addRoute with SEARCH as route method. |
post() |
(path: string, action: (e: T) => void): (Route<T>) |
POST is a shorthand for RouterGroup.addRoute with POST as route method. |
delete() |
(path: string, action: (e: T) => void): (Route<T>) |
DELETE is a shorthand for RouterGroup.addRoute with DELETE as route method. |
patch() |
(path: string, action: (e: T) => void): (Route<T>) |
PATCH is a shorthand for RouterGroup.addRoute with PATCH as route method. |
put() |
(path: string, action: (e: T) => void): (Route<T>) |
PUT is a shorthand for RouterGroup.addRoute with PUT as route method. |
head() |
(path: string, action: (e: T) => void): (Route<T>) |
HEAD is a shorthand for RouterGroup.addRoute with HEAD as route method. |
options() |
(path: string, action: (e: T) => void): (Route<T>) |
OPTIONS is a shorthand for RouterGroup.addRoute with OPTIONS as route method. |
hasRoute() |
(method: string, path: string): boolean |
HasRoute checks whether the specified route pattern (method + path) is registered in the current group or its children. |
router.Route
| Member | Type | |
|---|---|---|
action |
(e: T) => void |
|
method |
string |
|
path |
string |
|
middlewares |
Array<(hook.Handler<T> | undefined)> |
|
bindFunc() |
(...middlewareFuncs: ((e: T) => void)[]): (Route<T>) |
BindFunc registers one or multiple middleware functions to the current route. |
bind() |
(...middlewares: (hook.Handler<T> | undefined)[]): (Route<T>) |
Bind registers one or multiple middleware handlers to the current route. |
unbind() |
(...middlewareIds: string[]): (Route<T>) |
Unbind removes one or more middlewares with the specified id(s) from the current route. |
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.