seyfert/packages/rest/README.md
Marcos Susaña 87cdad0b03
Next: A complete Biscuit rewrite (#131)
* FINALLY WE REACHED AN AGREEMENT

* chore: d-types adapt

* websocket sucks, rest

* changes

* new look for core

* 💀

* fix cdn routes, more structures

Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>

* CDN routes

* chore: change to rome

Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>

* Oh shit, here we go again

Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>

* fixes

* mixin, handler events, ws
Co-authored-by: Yuzu
<yuzudev@users.noreply.github.com>
Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>

* change type

* Error system (#133)

* Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>

* chore: biscuit rebase

* token leak goes brrrr

* fix: events

* chore: road to raw data

* fix: managers typing

* chore: fix gateway typing

* feat: helpers

* style: linter

* Types for routes (#134)

* typing for routes

* managers

Co-authored-by: Marcos Susaña <marcosjgs03@gmail.com>

* Types for routes (#134)

* I wanna cry

* Next (#136)

* Merge #137

* chore: lineWidth to 140

* chore: README update

---------

Co-authored-by: Yuzu <yuzuru@programmer.net>
Co-authored-by: Free 公園 <FreeAoi@users.noreply.github.com>
Co-authored-by: ThisIsAName <46913407+NejireSupremacy@users.noreply.github.com>
Co-authored-by: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com>
Co-authored-by: MARCROCK22 <marcos22dev@gmail.com>
2023-05-29 22:34:47 -04:00

2.0 KiB

@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.

biscuit

Install (for node18)

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

Example (Standalone rest)

import { BiscuitREST } from "@biscuitland/rest";
import Fastify from "fastify";

const manager = new BiscuitREST({
    api: "http://any.rest.proxy/",
    version: 10,
    token: "your token goes here"
});

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..." });