mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
2.2 KiB
2.2 KiB
@biscuitland/rest
Install (for node18)
npm install @biscuitland/rest
yarn add @biscuitland/rest
Most importantly, biscuit's rest is:
A standalone rest library that is yet easy to use and easy to host on a serverless infrastructure, it is meant to be used with biscuit's libraries.
Example (Standalone rest)
import { DefaultRestAdapter } from "@biscuitland/rest";
import Fastify from "fastify";
const manager = new DefaultRestAdapter({
url: "http://localhost:port...",
token: "your token goes here",
version: 10,
});
const app = Fastify({});
app.all("*", (req, reply) => {
let response: unknown;
switch (req.method) {
case "GET":
response = await rest.get(req.url, req.body);
break;
case "POST":
response = await rest.post(req.url, req.body);
break;
case "PUT":
response = await rest.put(req.url, req.body);
break;
case "PATCH":
response = await rest.patch(req.url, req.body);
break;
case "DELETE":
response = await rest.delete(req.url, req.body);
break;
}
if (response)
reply.status(200).send({ status: 200, data: response });
else
reply.status(204).send({ status: 204, data: null });
});
app.listen({ port: "port..." });
This package can be delivered through unpkg however is not tested yet