Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Versions
Bridge
Developing now!π
This is an API framework that allows for the creation of a backend API and automatically generates frontend TS code to facilitate application development.
This framework is built on the Koa framework running within a Deno runtime, and utilizes some clever techniques to seamlessly integrate the frontend and backend components.
- β Auto-generate frontend API code!
- β Auto-generate API Mocking check code!
- β Ensure data safety with backend message validation!
Example
- routes/v1.ts:π write your api in a simple way
// we use zod to validate many data!
import { z, APIConfig } from "https://esm.sh/bridge";
// You must keep the api safe using zod
export const hello = new APIConfig(
// input Type validation
z.object({ data: z.string() }),
// output Type validation
z.object({
input: z.string(),
})
)
// create an api handle function to response data
.api((input) => {
return { input: input.data };
});- routes.ts:π₯ combine your module in a routes file
routes.ts is an independent module that needs to be used by the auto-generation script.
import * as v2 from "./routes/v2.ts";
import * as user from "./routes/user.ts";
import { APIConfig } from "../mod.ts";
// pick your routes in one ts file
export default { user, v2 } as unknown as Record<
string,
Record<string, APIConfig>
>;- main.ts:π start your apiοΌ
import { ServerInit } from "./deps.ts";
import modules from "./routes.ts";
ServerInit(modules as any);- build.ts:π€ create a build script to generate code!
import { buildAPI, buildTest } from "https://esm.sh/bridge/build/index.ts";
buildAPI(import.meta.resolve("./routes.ts"), "./dist/index.ts", {
root: "http://localhost:8000",
// for test, we need to replace package qs to Deno CDN
qs: "https://esm.sh/qs@6.11.1",
});
// buildTest for auto Test Check!π
buildTest(
import.meta.resolve("./routes.ts"),
import.meta.resolve("./dist/index.ts"),
"./dist/test.ts"
);- deno.jsonc:βοΈ make it easy to start project!
{
"tasks": {
"dev": "deno run --watch --allow-all --unstable main.ts",
"dev:build": "deno run --watch --allow-all --unstable build.ts"
},
"imports": {
// qs is used to handle e2e querystring
"qs": "https://esm.sh/qs@6.11.1",
"koa": "https://esm.sh/koa@2.14.1",
"@koa/router": "https://esm.sh/@koa/router@12.0.0",
"@koa/cors": "https://esm.sh/@koa/cors@4.0.0",
"koa-body": "https://esm.sh/koa-body@6.0.1",
"koa-logger": "https://esm.sh/koa-logger@3.2.1",
"zod": "https://esm.sh/zod@3.21.4"
}
}