Skip to content

Commit

Permalink
chore: improve examples (denoland#3377)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry authored and piscisaureus committed Nov 19, 2019
1 parent 00aa409 commit e6fdb26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
41 changes: 18 additions & 23 deletions std/http/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
# http

A framework for creating HTTP/HTTPS server.
```typescript
import { serve } from "https://deno.land/std/http/server.ts";
const body = new TextEncoder().encode("Hello World\n");
const s = serve({ port: 8000 });
console.log("http:https://localhost:8000/");
for await (const req of s) {
req.respond({ body });
}
```

### File Server

A small program for serving local files over HTTP

```sh
deno --allow-net --allow-read https://deno.land/std/http/file_server.ts
> HTTP server listening on http:https://0.0.0.0:4500/
```

## Cookie

Expand Down Expand Up @@ -50,25 +67,3 @@ console.log("Set-Cookie:", cookieHeader);
```

**Note**: At the moment multiple `Set-Cookie` in a `Response` is not handled.

## Example

```typescript
import { serve } from "https://deno.land/std/http/server.ts";
const s = serve("0.0.0.0:8000");
const body = new TextEncoder().encode("Hello World\n");

for await (const req of s) {
req.respond({ body });
}
```

### File Server

A small program for serving local files over HTTP.

Install it by using `deno install`

```sh
deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
```
8 changes: 4 additions & 4 deletions std/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,10 @@ are.
```ts
const { resources, close } = Deno;
console.log(resources());
// output like: { 0: "stdin", 1: "stdout", 2: "stderr", 3: "repl" }

// close resource by rid
close(3);
// { 0: "stdin", 1: "stdout", 2: "stderr" }
close(0);
console.log(resources());
// { "stdout", 2: "stderr" }
```

#### Metrics
Expand Down

0 comments on commit e6fdb26

Please sign in to comment.