@bit-js/quark
v0.1.5
Published
A fast framework for the Edge
Downloads
34
Readme
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 --devAn 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/quarkAn 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