Skip to content

Commit 7a20b7e

Browse files
committed
docs: improve examples
1 parent 9f58126 commit 7a20b7e

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ router.listen({ port: 5000 });
6666

6767
### Fetch handlers
6868

69-
For Cloudflare Workers the router needs to be configured and the router's fetch
70-
handler needs to be exported:
69+
For Cloudflare Workers the router needs to be configured and router needs to be
70+
the default export:
7171

7272
```ts
7373
import { Router } from "@oak/acorn";
@@ -84,7 +84,7 @@ router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);
8484

8585
router.listen({ port: 5000 });
8686

87-
export default { fetch: router.fetch };
87+
export default router;
8888
```
8989

9090
## Philosophy

mod.ts

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,66 @@
44
* Provides a router which specifically tailored for providing RESTful
55
* endpoints.
66
*
7-
* ## Using with Deno
7+
* acorn works across [Deno runtime](https://deno.com/),
8+
* [Deno Deploy](https://deno.com/deploy), [Node.js](https://nodejs.org/),
9+
* [Bun](https://bun.sh/),
10+
* and [Cloudflare Workers](https://workers.cloudflare.com/).
811
*
9-
* You need to reference the `@oak/acorn` package in code:
12+
* ## Installing
13+
*
14+
* @example Installing with Deno
15+
*
16+
* Add acorn to your project:
17+
*
18+
* ```
19+
* deno add @oak/acorn
20+
* ```
21+
*
22+
* @example Installing with Node.js or Cloudflare Workers
23+
*
24+
* Add acorn to your project with your preferred project manager.
25+
*
26+
* With npm:
27+
*
28+
* ```
29+
* npx jsr add @oak/acorn
30+
* ```
31+
*
32+
* With Yarn:
33+
*
34+
* ```
35+
* yarn dlx jsr add @oak/acorn
36+
* ```
37+
*
38+
* With pnpm:
39+
*
40+
* ```
41+
* pnpm dlx jsr add @oak/acorn
42+
* ```
43+
*
44+
* @example Install with Bun
45+
*
46+
* Add acorn to your project:
47+
*
48+
* ```
49+
* bunx jsr add @oak/acorn
50+
* ```
51+
*
52+
* ## Usage
53+
*
54+
* The main way of using acorn is to import the {@linkcode Router} into your
55+
* code and configure the router.
56+
*
57+
* If you are using Deno, Bun, or Node.js, after the router is configured,
58+
* invoke `.listen()` to start listening to requests.
59+
*
60+
* If you are using Cloudflare Workers, export the router as the default export
61+
* of the main module.
62+
*
63+
* @example Using with Deno, Bun and Node.js
1064
*
11-
* @example
1265
* ```ts
13-
* import { Router } from "jsr:@oak/acorn/router";
66+
* import { Router } from "@oak/acorn";
1467
*
1568
* const router = new Router();
1669
*
@@ -26,17 +79,8 @@
2679
* router.listen({ port: 3000 });
2780
* ```
2881
*
29-
* ## Using with Bun
30-
*
31-
* You need to install/add the package to your project via:
82+
* @example Using with Cloudflare Workers
3283
*
33-
* ```
34-
* bunx jsr add @oak/acorn
35-
* ```
36-
*
37-
* And then you import it into your project:
38-
*
39-
* @example
4084
* ```ts
4185
* import { Router } from "@oak/acorn/router";
4286
*
@@ -51,7 +95,7 @@
5195
*
5296
* router.get("/books/:id", (ctx) => BOOKS[ctx.params.id]);
5397
*
54-
* router.listen({ port: 3000 });
98+
* export default router;
5599
* ```
56100
*
57101
* @module

0 commit comments

Comments
 (0)