0.1.5 • Published 1 year ago

@bit-js/quark v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Quark

Yet another Cloudflare framework.

Getting Started

Cloudflare

Install @bit-js/quark with @cloudflare/workers-types.

npm i @bit-js/quark
npm i @cloudflare/workers-types --dev

An example Hello world app:

import { Quark } from "@bit-js/quark";

const app = new Quark()
  .use((ctx) => {
    // TODO: Cache the header if it is static
    ctx.headers.push(["Content-Type", "text/plain"]);
    return ctx.next();
  })
  .get("/", (ctx) => ctx.body("Hello world"));

export default app;

To access ExecutionContext and Env:

(ctx) => {
  // Environment variables
  ctx.env;

  // Execution context
  ctx.execution;
};

To overwrite Env types:

declare global {
  interface Env {
    MY_ENV_VAR: string;
    MY_SECRET: string;
    myKVNamespace: KVNamespace;
  }
}

To use Quark with service workers:

addEventListener("fetch", app.handleEvent);

Deno

An example Hello world app:

import { Quark } from "npm:@bit-js/quark";

const app = new Quark()
  .use((ctx) => {
    // TODO: Cache the header if it is static
    ctx.headers.push(["Content-Type", "text/plain"]);
    return ctx.next();
  })
  .get("/", (ctx) => ctx.body("Hello world"));

export default app;

Others

Install @bit-js/quark:

npm i @bit-js/quark

An example Hello world app:

import { Quark } from "@bit-js/quark";

const app = new Quark()
  .use((ctx) => {
    ctx.headers["Content-Type"] = "text/plain";
    return ctx.next();
  })
  .get("/", (ctx) => ctx.body("Hello world"));

export default app;

Client

Export your app type:

export type TApp = typeof app;

Usage on client:

import type { TApp } from "../server";
import { client } from "@bit-js/quark";

const app = client<TApp>("http://localhost:3000");

const res = await app.get("/");
await res.text(); // Hello world
0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago