Skip to content

Commit

Permalink
docs: update inline docs and readme around Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Mar 7, 2024
1 parent f09b303 commit 297a38f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
[![ci](https://github.com/oakserver/acorn/workflows/ci/badge.svg)](https://github.com/oakserver/acorn)

Rapidly develop and iterate on RESTful APIs using a strongly typed router
designed for Deno CLI and Deno Deploy.
designed for Deno CLI, Deno Deploy and Bun.

## Usage

### Under Deno CLI or Deploy

You need to import the package into your code:

```ts
import { Router } from "jsr:@oak/acorn/router";
Expand All @@ -21,9 +27,35 @@ router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);
router.listen({ port: 5000 });
```

### Under Bun

You need to add the package to your project:

```
bunx jsr add @oak/acorn
```

Then you need to import the package into your code:

```ts
import { Router } from "@oak/acorn/router";

const BOOKS: Record<string, { id: number; title: string }> = {
"1": { id: 1, title: "The Hound of the Baskervilles" },
"2": { id: 2, title: "It" },
};

const router = new Router();

router.get("/", () => ({ hello: "world" }));
router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);

router.listen({ port: 5000 });
```

## Philosophy

After having spent years working on [oak](https://deno.land/x/oak) and extensive
After having spent years working on [oak](https://jsr.io/@oak/oak) and extensive
experience with building Deno, that really when people were looking at
middleware type of solution, really what they were looking fore was a straight
forward router that made it easy to handle JSON payloads.
Expand Down
32 changes: 32 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Provides a router which specifically tailored for providing RESTful
* endpoints.
*
* ## Using with Deno
*
* You need to reference the `@oak/acorn` package in code:
*
* @example
* ```ts
* import { Router } from "jsr:@oak/acorn/router";
Expand All @@ -22,6 +26,34 @@
* router.listen({ port: 3000 });
* ```
*
* ## Using with Bun
*
* You need to install/add the package to your project via:
*
* ```
* bunx jsr add @oak/acorn
* ```
*
* And then you import it into your project:
*
* @example
* ```ts
* import { Router } from "@oak/acorn/router";
*
* const router = new Router();
*
* router.get("/", () => ({ hello: "world" }));
*
* const BOOKS = {
* "1": { title: "The Hound of the Baskervilles" },
* "2": { title: "It" },
* };
*
* router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);
*
* router.listen({ port: 3000 });
* ```
*
* @module
*/

Expand Down

0 comments on commit 297a38f

Please sign in to comment.