The HTTP request object.
A function to call the next middleware or route handler.
A promise resolving to an HTTP response.
Example of a middleware function:
import { start, router, text, type Middleware } from "@pulsar-http/core";
const logMiddleware: Middleware = async (req, next) => {
const response = await next();
console.log(`Request ${req.method} ${req.url} - Response ${response.status}`);
return response;
};
const routes = [
router.get("/", async () => text("Hello, World!")),
];
start({ routes, middlewares: [logMiddleware] });
In this example, the logMiddleware
will wait for the next middleware or route handler to finish processing the request, log the request and response information, and then return the response.
Type of middleware function that processes the request before or after the main route handler.