Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youngjuning/duck
Simple dynamic router register for Deno
https://github.com/youngjuning/duck
deno duck router router-register
Last synced: 14 days ago
JSON representation
Simple dynamic router register for Deno
- Host: GitHub
- URL: https://github.com/youngjuning/duck
- Owner: youngjuning
- License: mit
- Created: 2020-08-05T06:19:55.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T17:58:23.000Z (over 4 years ago)
- Last Synced: 2024-12-15T18:46:57.271Z (about 1 month ago)
- Topics: deno, duck, router, router-register
- Language: TypeScript
- Homepage: https://deno.land/x/duck
- Size: 25.4 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-deno-cn - @youngjuning/duck
README
# duck
A simple controller scanner and router register for deno!
## API
> duck(router, controller_dir: string = 'controllers')
## Usage
### oak
```ts
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import duck from "https://deno.land/x/duck/mod.ts";const app = new Application();
const router = new Router();
const gaga = await duck(router);app.use(gaga.routes());
app.use(gaga.allowedMethods());console.log(`🦕 oak server running at http://127.0.0.1:1998/ 🦕`);
await app.listen({ port: 1998 });
```Your controllers just like: `controllers/helloworld.ts`:
```ts
import { Context } from "../deps.ts";export const name = "helloworld";
export const method = "get";export default async (ctx: Context) => {
const { response } = ctx;
response.body = "hello world!";
};
```### servest
```ts
import { createApp } from "https://servestjs.org/@v1.1.1/mod.ts";
import duck from "https://deno.land/x/duck/mod.ts";const app = createApp();
const gaga = await duck(app);
gaga.listen({ port: 1998 });console.log(`🦕 servest server running at http://127.0.0.1:1998/ 🦕`);
```Your controllers just like: `controllers/helloworld.ts`:
```ts
import { ServerRequest } from "https://servestjs.org/@v1.1.1/mod.ts";export const name = "helloworld";
export const method = "get";export default async (req: ServerRequest) => {
await req.respond({
status: 200,
body: "Hello World!",
})
};
```### abc
```ts
import { Application } from "https://deno.land/x/abc@v1/mod.ts";
import duck from "https://deno.land/x/duck/mod.ts";
const app = new Application();
const gaga = await duck(app);gaga.start({ port: 1998 });
console.log(`🦕 abc server running at http://127.0.0.1:1998/ 🦕`);
```Your controllers just like: `controllers/helloworld.ts`:
```ts
import { Context } from "https://deno.land/x/abc@v1/mod.ts";export const name = "helloworld";
export const method = "get";export default async (ctx: Context) => {
return 'Hello World!'
};
```