static/jsvm/interfaces/router.Router.html
Router defines a thin wrapper around the standard Go [http.ServeMux] by adding support for routing sub-groups, middlewares and other common utils.
Example:
r := NewRouter[*MyEvent](eventFactory) // middlewares r.BindFunc(m1, m2) // routes r.GET("/test", handler1) // sub-routers/groups api := r.Group("/api") api.GET("/admins", handler2) // generate a http.ServeMux instance based on the router configurations mux, _ := r.BuildMux() http.ListenAndServe("localhost:8090", mux)Copy
anybindbindFuncbuildMuxdeletegetgrouphasRouteheadoptionspatchpostputroutesearchunbind
Any is a shorthand for [RouterGroup.AddRoute] with "" as route method (aka. matches any method).
-
- (e): void
-
-
Bind registers one or multiple middleware handlers to the current group.
Rest ...middlewares: hook.Handler<T>[]BindFunc registers one or multiple middleware functions to the current group.
The registered middleware functions are "anonymous" and with default priority, aka. executes in the order they were registered.
If you need to specify a named middleware (ex. so that it can be removed) or middleware with custom exec prirority, use [RouterGroup.Bind] method.
Rest ...middlewareFuncs: ((e) => void)[]BuildMux constructs a new mux [http.Handler] instance from the current router configurations.
DELETE is a shorthand for [RouterGroup.AddRoute] with DELETE as route method.
-
- (e): void
-
-
GET is a shorthand for [RouterGroup.AddRoute] with GET as route method.
-
- (e): void
-
-
Group creates and register a new child Group into the current one with the specified prefix.
The prefix follows the standard Go net/http ServeMux pattern format ("[HOST]/[PATH]") and will be concatenated recursively into the final route path, meaning that only the root level group could have HOST as part of the prefix.
Returns the newly created group to allow chaining and registering sub-routes and group specific middlewares.
HasRoute checks whether the specified route pattern (method + path) is registered in the current group or its children.
This could be useful to conditionally register and checks for routes in order prevent panic on duplicated routes.
Note that routes with anonymous and named wildcard placeholder are treated as equal, aka. "GET /abc/" is considered the same as "GET /abc/{something...}".
HEAD is a shorthand for [RouterGroup.AddRoute] with HEAD as route method.
-
- (e): void
-
-
OPTIONS is a shorthand for [RouterGroup.AddRoute] with OPTIONS as route method.
-
- (e): void
-
-
PATCH is a shorthand for [RouterGroup.AddRoute] with PATCH as route method.
-
- (e): void
-
-
POST is a shorthand for [RouterGroup.AddRoute] with POST as route method.
-
- (e): void
-
-
PUT is a shorthand for [RouterGroup.AddRoute] with PUT as route method.
-
- (e): void
-
-
Route registers a single route into the current group.
Note that the final route path will be the concatenation of all parent groups prefixes + the route path. The path follows the standard Go net/http ServeMux format ("[HOST]/[PATH]"), meaning that only a top level group route could have HOST as part of the prefix.
Returns the newly created route to allow attaching route-only middlewares.
-
- (e): void
-
-
SEARCH is a shorthand for [RouterGroup.AddRoute] with SEARCH as route method.
-
- (e): void
-
-
Unbind removes one or more middlewares with the specified id(s) from the current group and its children (if any).
Anonymous middlewares are not removable, aka. this method does nothing if the middleware id is an empty string.
Rest ...middlewareIds: string[]middlewares: hook.Handler<T>[]
prefix: string
OSLightDark
Generated using TypeDoc