Skip to content

Commit 26ae6bd

Browse files
committed
docs: update info around .handle method
Closes #680
1 parent 13f0295 commit 26ae6bd

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ import { Application } from "https://deno.land/x/oak/mod.ts";
5050
To use from JSR, import into a module:
5151

5252
```ts
53-
import { Application } from "jsr:@oak/oak@14";
53+
import { Application } from "jsr:@oak/oak";
54+
```
55+
56+
Or use the Deno CLI to add it to your project:
57+
58+
```
59+
deno add jsr:@oak/oak
5460
```
5561

5662
### Node.js
@@ -60,7 +66,7 @@ oak is available for Node.js on both
6066
[JSR](https://jsr.io/@oak/oak). To use from npm, install the package:
6167

6268
```
63-
npm i @oakserver/oak@14
69+
npm i @oakserver/oak
6470
```
6571

6672
And then import into a module:
@@ -72,7 +78,7 @@ import { Application } from "@oakserver/oak";
7278
To use from JSR, install the package:
7379

7480
```
75-
npx jsr i @oak/oak@14
81+
npx jsr i @oak/oak
7682
```
7783

7884
And then import into a module:
@@ -95,7 +101,7 @@ oak is available for [Cloudflare Workers](https://workers.cloudflare.com/) on
95101
project:
96102

97103
```
98-
npx jsr add @oak/oak@14
104+
npx jsr add @oak/oak
99105
```
100106

101107
And then import into a module:
@@ -128,7 +134,7 @@ oak is available for Bun on [JSR](https://jsr.io/@oak/oak). To use install the
128134
package:
129135

130136
```
131-
bunx jsr i @oak/oak@14
137+
bunx jsr i @oak/oak
132138
```
133139

134140
And then import into a module:
@@ -234,19 +240,10 @@ app.use((ctx) => {
234240
ctx.response.body = "Hello World!";
235241
});
236242

237-
const listener = Deno.listen({ hostname: "localhost", port: 8000 });
238-
239-
for await (const conn of listener) {
240-
(async () => {
241-
const requests = Deno.serveHttp(conn);
242-
for await (const { request, respondWith } of requests) {
243-
const response = await app.handle(request, conn);
244-
if (response) {
245-
respondWith(response);
246-
}
247-
}
248-
});
249-
}
243+
Deno.serve(async (request, info) => {
244+
const res = await app.handle(request, info.remoteAddr);
245+
return res ?? Response.error();
246+
});
250247
```
251248

252249
An instance of application has some properties as well:

application.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* # Example
99
*
1010
* ```ts
11-
* import { Application } from "jsr:@oak/oak@14/application";
11+
* import { Application } from "jsr:@oak/oak/application";
1212
*
1313
* const app = new Application();
1414
* app.use((ctx) => {
@@ -731,8 +731,7 @@ export class Application<AS extends State = Record<string, any>>
731731
* is similar to `.listen()`, but opening the connection and retrieving
732732
* requests are not the responsibility of the application. If the generated
733733
* context gets set to not to respond, then the method resolves with
734-
* `undefined`, otherwise it resolves with a request that is compatible with
735-
* `std/http/server`. */
734+
* `undefined`, otherwise it resolves with a standard {@linkcode Response}. */
736735
handle: HandleMethod = (async (
737736
request: Request,
738737
secureOrAddr: NetAddr | boolean | undefined,

router.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* # Example
88
*
99
* ```ts
10-
* import { Application } from "jsr:@oak/oak@14/application";
11-
* import { Router } from "jsr:@oak/oak@14/router";
10+
* import { Application } from "jsr:@oak/oak/application";
11+
* import { Router } from "jsr:@oak/oak/router";
1212
*
1313
* const app = new Application();
1414
* const router = new Router();

0 commit comments

Comments
 (0)