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

Commit

Permalink
Update http_server.md to use Deno.serve (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Sep 13, 2023
1 parent b9775ea commit 55fa96a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions examples/http_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
With just a few lines of code you can run your own HTTP web server with control
over the response status, request headers and more.

## Sample web server
## Using the `Deno.listen`

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

Expand Down Expand Up @@ -57,19 +57,11 @@ deno run --allow-net webserver.ts

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

### Using the `std/http` library

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

**webserver.ts**:

```ts
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";

const port = 8080;

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

console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
await serve(handler, { port });
Deno.serve({ port }, handler);
```

Then run this with:
Expand Down

0 comments on commit 55fa96a

Please sign in to comment.