diff options
author | Ry Dahl <ry@tinyclouds.org> | 2019-11-19 01:07:13 -0500 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2019-11-18 22:07:13 -0800 |
commit | e6fdb2628fdeeae0c7b06c25214b2edba96364dd (patch) | |
tree | b42eed4df1ab0f366194934898eed0e11846f05f /std/http/README.md | |
parent | 00aa409ff228a8fe6c73677012538844ce96a3ec (diff) |
chore: improve examples (#3377)
Diffstat (limited to 'std/http/README.md')
-rw-r--r-- | std/http/README.md | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/std/http/README.md b/std/http/README.md index 26fe25bf6..459c8e286 100644 --- a/std/http/README.md +++ b/std/http/README.md @@ -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 -``` |