seyfert/packages/rest/README.md
2022-08-01 20:37:46 -05:00

1.6 KiB

biscuit

A brand new bleeding edge non bloated Discord library

biscuit

Install (for node18)

npm install @biscuitland/rest
yarn add @biscuitland/rest

for further reading join our Discord

Most importantly, biscuit's rest is:

An standalone rest library that is yet easy to use and easy to host on a serverless infraestructure, it is meant to be used with biscuit's libraries

Example

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