1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00

chore: improve examples (#3377)

This commit is contained in:
Ry Dahl 2019-11-19 01:07:13 -05:00 committed by Bert Belder
parent 00aa409ff2
commit e6fdb2628f
2 changed files with 22 additions and 27 deletions

View file

@ -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://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://0.0.0.0:4500/
```
## Cookie
@ -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
```

View file

@ -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