summaryrefslogtreecommitdiff
path: root/http/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'http/README.md')
-rw-r--r--http/README.md19
1 files changed, 5 insertions, 14 deletions
diff --git a/http/README.md b/http/README.md
index 67c578f31..2c9a90853 100644
--- a/http/README.md
+++ b/http/README.md
@@ -5,22 +5,13 @@ A framework for creating HTTP/HTTPS server.
## Example
```typescript
-import { createServer } from "https://deno.land/x/http/server.ts";
-import { encode } from "https://deno.land/x/strings/strings.ts";
+import { serve } from "https://deno.land/x/http/server.ts";
+const s = serve("0.0.0.0:8000");
async function main() {
- const server = createServer();
- server.handle("/", async (req, res) => {
- await res.respond({
- status: 200,
- body: encode("ok")
- });
- });
- server.handle(new RegExp("/foo/(?<id>.+)"), async (req, res) => {
- const { id } = req.match.groups;
- await res.respondJson({ id });
- });
- server.listen("127.0.0.1:8080");
+ for await (const req of s) {
+ req.respond({ body: new TextEncoder().encode("Hello World\n") });
+ }
}
main();