Skip to content

Commit

Permalink
docs: update info around .handle method
Browse files Browse the repository at this point in the history
Closes #680
  • Loading branch information
kitsonk committed Nov 23, 2024
1 parent 13f0295 commit 26ae6bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ import { Application } from "https://deno.land/x/oak/mod.ts";
To use from JSR, import into a module:

```ts
import { Application } from "jsr:@oak/oak@14";
import { Application } from "jsr:@oak/oak";
```

Or use the Deno CLI to add it to your project:

```
deno add jsr:@oak/oak
```

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

```
npm i @oakserver/oak@14
npm i @oakserver/oak
```

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

```
npx jsr i @oak/oak@14
npx jsr i @oak/oak
```

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

```
npx jsr add @oak/oak@14
npx jsr add @oak/oak
```

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

```
bunx jsr i @oak/oak@14
bunx jsr i @oak/oak
```

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

const listener = Deno.listen({ hostname: "localhost", port: 8000 });

for await (const conn of listener) {
(async () => {
const requests = Deno.serveHttp(conn);
for await (const { request, respondWith } of requests) {
const response = await app.handle(request, conn);
if (response) {
respondWith(response);
}
}
});
}
Deno.serve(async (request, info) => {
const res = await app.handle(request, info.remoteAddr);
return res ?? Response.error();
});
```

An instance of application has some properties as well:
Expand Down
5 changes: 2 additions & 3 deletions application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* # Example
*
* ```ts
* import { Application } from "jsr:@oak/oak@14/application";
* import { Application } from "jsr:@oak/oak/application";
*
* const app = new Application();
* app.use((ctx) => {
Expand Down Expand Up @@ -731,8 +731,7 @@ export class Application<AS extends State = Record<string, any>>
* is similar to `.listen()`, but opening the connection and retrieving
* requests are not the responsibility of the application. If the generated
* context gets set to not to respond, then the method resolves with
* `undefined`, otherwise it resolves with a request that is compatible with
* `std/http/server`. */
* `undefined`, otherwise it resolves with a standard {@linkcode Response}. */
handle: HandleMethod = (async (
request: Request,
secureOrAddr: NetAddr | boolean | undefined,
Expand Down
4 changes: 2 additions & 2 deletions router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* # Example
*
* ```ts
* import { Application } from "jsr:@oak/oak@14/application";
* import { Router } from "jsr:@oak/oak@14/router";
* import { Application } from "jsr:@oak/oak/application";
* import { Router } from "jsr:@oak/oak/router";
*
* const app = new Application();
* const router = new Router();
Expand Down

0 comments on commit 26ae6bd

Please sign in to comment.