Skip to content

Commit

Permalink
Implemented Server.all() & Router.all() alias method of any() to impr…
Browse files Browse the repository at this point in the history
…ove ExpressJS compatibility
  • Loading branch information
kartikk221 committed May 25, 2022
1 parent a8104f5 commit 5126de2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/Router.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ webserver.use('/api/v1', api_v1_router);
* **Example:** A `GET /users/:id` route from a `Router` used with `use('/api/v1', router)` call will be created as `GET /api/v1/users/:id`.
* **Example:** A middleware assigned directly to a `Router` used with `use('/api', router)` will execute for all routes that begin with `/api`.
* `any(...4 Overloads)`: Creates an HTTP route on the specified pattern. Alias methods are listed below for all available HTTP methods.
* **Alias Methods:** `get()`, `post()`, `put() `, `delete()`, `head()`, `options()`, `patch()`, `trace()`, `connect()`, `upgrade()`.
* **Alias Methods:** `all()`, `get()`, `post()`, `put() `, `delete()`, `head()`, `options()`, `patch()`, `trace()`, `connect()`, `upgrade()`.
* **Overload Types**:
* `any(String: pattern, Function: handler)`: Creates an `any` method HTTP route with the specified `handler`.
* `any(String: pattern, Object: options, Function: handler)`: Creates an `any` method HTTP route with the specified route `options` and `handler`.
Expand Down
2 changes: 1 addition & 1 deletion docs/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Below is a breakdown of the `Server` component which is an extended `Router` ins
* **Note** `pattern` is treated as a wildcard match by default and does not support `*`/`:param` prefixes.
* **See** [`> [Router]`](./Router.md) & [`> [Middlewares]`](./Middlewares.md) for **full documentation** on this method.
* `any(...4 Overloads)`: Creates an HTTP route on the specified pattern. Alias methods are listed below for all available HTTP methods.
* **Alias Methods:** `get()`, `post()`, `put()`, `delete()`, `head()`, `options()`, `patch()`, `trace()`, `connect()`, `upgrade()`, `ws()`.
* **Alias Methods:** `all()`, `get()`, `post()`, `put()`, `delete()`, `head()`, `options()`, `patch()`, `trace()`, `connect()`, `upgrade()`, `ws()`.
* **Overload Types**:
* `any(String: pattern, Function: handler)`: Creates an any method HTTP route with the specified `handler`.
* `any(String: pattern, Object: options, Function: handler)`: Creates an any method HTTP route with the specified `options` and `handler`.
Expand Down
13 changes: 13 additions & 0 deletions src/components/router/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ class Router {
return this._register_route('any', ...arguments);
}

/**
* Alias of any() method.
* Creates an HTTP route that handles any HTTP method requests.
* Note! ANY routes do not support route specific middlewares.
*
* @param {String} pattern
* @param {...(RouteOptions|MiddlewareHandler)} args
*/
all() {
// Alias of any() method
return this.any(...arguments);
}

/**
* Creates an HTTP route that handles GET method requests.
*
Expand Down
12 changes: 12 additions & 0 deletions types/components/router/Router.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ export class Router {
any(pattern: string, ...handlers: [...MiddlewareHandler[], UserRouteHandler]): void;
any(pattern: string, options: UserRouteOptions, ...handlers: [...MiddlewareHandler[], UserRouteHandler]): void;

/**
* Alias of any() method.
* Creates an HTTP route that handles any HTTP method requests.
* Note! ANY routes do not support route specific middlewares.
*
* @param {String} pattern
* @param {...(RouteOptions|MiddlewareHandler)} args
*/
all(pattern: string, handler: UserRouteHandler): void;
all(pattern: string, ...handlers: [...MiddlewareHandler[], UserRouteHandler]): void;
all(pattern: string, options: UserRouteOptions, ...handlers: [...MiddlewareHandler[], UserRouteHandler]): void;

/**
* Creates an HTTP route that handles GET method requests.
*
Expand Down

0 comments on commit 5126de2

Please sign in to comment.