Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit 55fa96a

Browse files
authored
Update http_server.md to use Deno.serve (#734)
1 parent b9775ea commit 55fa96a

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

examples/http_server.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
With just a few lines of code you can run your own HTTP web server with control
1010
over the response status, request headers and more.
1111

12-
## Sample web server
12+
## Using the `Deno.listen`
1313

1414
In this example, the user-agent of the client is returned to the client:
1515

@@ -57,19 +57,11 @@ deno run --allow-net webserver.ts
5757

5858
Then navigate to `http://localhost:8080/` in a browser.
5959

60-
### Using the `std/http` library
61-
62-
> ℹ️ Since
63-
> [the stabilization of _native_ HTTP bindings in
64-
`^1.13.x`](https://deno.com/blog/v1.13#stabilize-native-http-server-api),
65-
> std/http now supports a _native_ HTTP server from ^0.107.0. The legacy server
66-
> module was removed in 0.117.0.
60+
### Using the `Deno.serve`
6761

6862
**webserver.ts**:
6963

7064
```ts
71-
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";
72-
7365
const port = 8080;
7466

7567
const handler = (request: Request): Response => {
@@ -81,7 +73,7 @@ const handler = (request: Request): Response => {
8173
};
8274

8375
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
84-
await serve(handler, { port });
76+
Deno.serve({ port }, handler);
8577
```
8678

8779
Then run this with:

0 commit comments

Comments
 (0)