From 3197cad0f83d921b42dc79413836ff9e0efeaa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Aug 2021 10:19:02 +0200 Subject: [PATCH] chore: update README.md (#11633) Updates "complex" example in the README.md, which used std/http which will be phased out. Instead use newly stabilized Deno.serveHttp() --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 379721a56a..f5ac6f1ee0 100644 --- a/README.md +++ b/README.md @@ -72,11 +72,17 @@ deno run https://deno.land/std/examples/welcome.ts Or a more complex one: ```ts -import { serve } from "https://deno.land/std/http/server.ts"; -const s = serve({ port: 8000 }); +const listener = Deno.listen({ port: 8000 }); console.log("http://localhost:8000/"); -for await (const req of s) { - req.respond({ body: "Hello World\n" }); + +for await (const conn of listener) { + serve(conn); +} + +async function serve(conn: Deno.Conn) { + for await (const { respondWith } of Deno.serveHttp(conn)) { + respondWith(new Response("Hello world")); + } } ```