Skip to content

Commit 9337a91

Browse files
authored
Merge pull request jeremydaly#92 from jeremydaly/v0.10.0
v0.10.0 updates
2 parents cc87ed5 + f9e7af1 commit 9337a91

2 files changed

Lines changed: 29 additions & 17 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
### Lightweight web framework for your serverless applications
99

10-
Lambda API is a lightweight web framework for use with AWS Lambda using AWS API Gateway Lambda Proxy Integration or ALB Lambda Target Support. This closely mirrors (and is based on) other web frameworks like Express.js and Fastify, but is significantly stripped down to maximize performance with Lambda's stateless, single run executions.
10+
Lambda API is a lightweight web framework for AWS Lambda using AWS API Gateway Lambda Proxy Integration or ALB Lambda Target Support. This closely mirrors (and is based on) other web frameworks like Express.js and Fastify, but is significantly stripped down to maximize performance with Lambda's stateless, single run executions.
1111

1212
## Simple Example
1313

@@ -1321,7 +1321,7 @@ Conditional route support could be added via middleware or with conditional logi
13211321
## Execution Stacks
13221322
Lambda API v0.10 introduced execution stacks as a way to more efficiently process middleware. Execution stacks are automatically created for you when adding routes and middleware using the standard route convenience methods, as well as `METHOD()` and `use()`. This is a technical implementation that has made method-based middleware and additional wildcard functionality possible.
13231323

1324-
Execution stacks are backwards compatible, so no code changes need to be made when upgrading from a lower version. The only caveat is with matching middleware to specific parameterized paths. Path-based middleware creates mount points that require methods to execute. This means that a `/users/:userId` middleware path, would not execute if you defined a `/users/test` path.
1324+
Execution stacks are backwards compatible, so no code changes need to be made when upgrading from a lower version. The only caveat is with matching middleware to specific parameterized paths. Path-based middleware creates mount points that require methods to execute. This means that a `/users/:userId` middleware path would not execute if you defined a `/users/test` path.
13251325

13261326
Execution stacks allow you to execute multiple middlewares based on a number of factors including path and method. For example, you can specify a global middleware to run on every `/user/*` route, with additional middleware running on just `/user/settings/*` routes, with more middleware running on just `GET` requests to `/users/settings/name`. Execution stacks inherit middleware from matching routes and methods higher up the stack, building a final stack that is unique to each route. Definition order also matters, meaning that routes defined *before* global middleware **will not** have it as part of its execution stack. The same is true of any wildcard-based route, giving you flexibility and control over when middleware is applied.
13271327

index.d.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export declare interface App {
3939
export declare type Middleware = (req: Request, res: Response, next: Middleware) => void;
4040
export declare type ErrorHandlingMiddleware = (error: Error, req: Request, res: Response, next: ErrorHandlingMiddleware) => void;
4141
export declare type ErrorCallback = (error?: Error) => void;
42-
export declare type HandlerFunction = (req: Request, res: Response) => void | {} | Promise<{}>;
42+
export declare type HandlerFunction = (req: Request, res: Response, next?: NextFunction) => void | {} | Promise<{}>;
4343
export declare type LoggerFunction = (message: string) => void;
4444
export declare type NextFunction = () => void;
4545
export declare type TimestampFunction = () => string;
@@ -175,20 +175,32 @@ export declare class API {
175175
app(namespace: string, handler: HandlerFunction): App;
176176
app(options: App): App;
177177

178-
get(path: string, handler: HandlerFunction): void;
179-
post(path: string, handler: HandlerFunction): void;
180-
put(path: string, handler: HandlerFunction): void;
181-
patch(path: string, handler: HandlerFunction): void;
182-
delete(path: string, handler: HandlerFunction): void;
183-
options(path: string, handler: HandlerFunction): void;
184-
head(path: string, handler: HandlerFunction): void;
185-
any(path: string, handler: HandlerFunction): void;
186-
METHOD(method: METHODS, path: string, handler: HandlerFunction): void;
187-
188-
189-
use(paths: string[], middleware: Middleware);
190-
use (middleware: Middleware);
191-
use (errorHandlingMiddleware: ErrorHandlingMiddleware);
178+
get(path: string, ...handler: HandlerFunction[]): void;
179+
get(...handler: HandlerFunction[]): void;
180+
post(path: string, ...handler: HandlerFunction[]): void;
181+
post(...handler: HandlerFunction[]): void;
182+
put(path: string, ...handler: HandlerFunction[]): void;
183+
put(...handler: HandlerFunction[]): void;
184+
patch(path: string, ...handler: HandlerFunction[]): void;
185+
patch(...handler: HandlerFunction[]): void;
186+
delete(path: string, ...handler: HandlerFunction[]): void;
187+
delete(...handler: HandlerFunction[]): void;
188+
options(path: string, ...handler: HandlerFunction[]): void;
189+
options(...handler: HandlerFunction[]): void;
190+
head(path: string, ...handler: HandlerFunction[]): void;
191+
head(...handler: HandlerFunction[]): void;
192+
any(path: string, ...handler: HandlerFunction[]): void;
193+
any(...handler: HandlerFunction[]): void;
194+
METHOD(method: METHODS, path: string, ...handler: HandlerFunction[]): void;
195+
METHOD(method: METHODS, ...handler: HandlerFunction[]): void;
196+
197+
198+
199+
200+
use(path: string, ...middleware: Middleware[]);
201+
use(paths: string[], ...middleware: Middleware[]);
202+
use (...middleware: Middleware[]);
203+
use (...errorHandlingMiddleware: ErrorHandlingMiddleware[]);
192204

193205
finally(callback: FinallyFunction): void;
194206

0 commit comments

Comments
 (0)