@leverage/plugin-http
A HTTP plugin for Leverage.
Install
# Using NPM
npm install @leverage/plugin-http
# Using Yarn
yarn add @leverage/plugin-http
Documentation
Plugin Install
To install the HTTP Plugin, add http to Leverage.
import { add } from "@leverage/core";
import { http } from "@leverage/plugin-http";
add(http);
Events
The HTTP Plugin can be configured using events. The server can also be told to start listening.
import { add, emit } from "@leverage/core";
import { http } from "@leverage/plugin-http";
add(http);
await emit("http:configure", {
ignoreTrailingSlash: true,
});
await signal("http:listen", {
port: 8080,
});
Components
A HTTP component holds configuration for a route.
import { useHTTP } from "@leverage/plugin-http";
export const init = () => {
useHTTP({
path: "/hello-world",
method: "GET",
});
};
export const handler = (request, reply) => {
};
export const preHandler = (request, reply) => {
};
export const onSend = (request, reply) => {
};
Additionally, connect-style middleware can be used by exporting a middleware function.
import { useHTTP } from "@leverage/plugin-http";
import cors from "cors";
export const init = () => {
useHTTP();
};
export const middleware = cors();
Hooks
useHTTP
The useHTTP hook can be used to configure an HTTP component.
import { useHTTP } from "@leverage/plugin-http";
export const init = () => {
useHTTP({
path: "/hello-world",
method: "GET",
});
};
import { useHTTP } from "@leverage/plugin-http";
export const init = () => {
useHTTP();
};