HTTP middleware specification
Define standard HTTP middleware specifications. This is intended to increase the interoperability of the HTTP library's own middleware.
It consists only of the web standards stack and is compatible with many browsers.
- Upstream
- Refers to HTTP requests forwarded from the client to the server.
- Downstream
- Refers to the HTTP response forwarded from the server to the client.
Middleware interfaces can be defined in TypeScript as follows:
interface Middleware {
(request: Request, next: Handler): Response | Promise<Response>;
}
interface Handler {
(request: Request): Response | Promise<Response>;
}
Middleware
has the following features:
-
Compliant with Fetch API.
-
Compliant with
Handler
.Handler
is a powerful interface for handling HTTP requests. TheMiddleware
is purely an extension and compatibility withHandler
. -
It is a pure function.
Middleware
is a pure function that returns a value. Implementations are expected to have no side effects. -
It is self-contained.
-
It can handle upstream.
-
It can handle downstream.
-
It can handle next handler.
See chain-handler for a concrete implementation that can handle middleware
Copyright © 2023-present httpland.
Released under the MIT license