A set of interfaces describing the functionality of an HTTP request handler.
npm install @n7e/http-handlerA set of interfaces describing the functionality of an HTTP request handler.
For further insights, read on.
- Installation
- Request Handler
- Middleware
- Middleware Request Handler
To install this library use your favorite package manager. No additional
steps are required to start using the library.
``shell`
npm install @n7e/http-handler
*This library only contains a set of interfaces and is less than useless if you
don't use TypeScript.*
The concept of a request handler is some procedure able to produce an
appropriate response from a given request. These kinds of procedures are central
to HTTP servers as well as clients. Since this kind of procedure is very common
this library provides an abstraction in the form of a RequestHandler
interface.
This library does not provide an implementation but there may be dependant
libraries that does.
*RequestHandler is just an interface describing the functionality of a request
handler. To create a request handler instance you need to reference a specific
implementation.*
The concept of middleware is similar to that of a
request handler with the addition of a request handler
delegate to resume the middleware chain. Since this paradigm, similar to that of
a request handler is very useful for both HTTP servers and
clients this library provides an abstraction in the form of a Middleware
interface.
This library does not provide an implementation but there may be dependant
libraries that does.
*Middleware is just an interface describing the functionality of HTTP
middleware. To create a middleware instance you need to reference a specific
implementation.*
For convenience a request handler is provided that uses a set of middleware to
process the request before delegating to a fallback request handler. If any of
the provided middleware produces a response no further middleware nor the
fallback request handler will be invoked.
`typescript
import { MiddlewareRequestHandler } from "@n7e/http-handler";
const requestHandler = new MiddlewareRequestHandler([], fallbackRequestHandler);
``