Deno: better http server API

Created on 29 Oct 2019  路  6Comments  路  Source: denoland/deno

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(s.url);
for await (const req of s) {
  req.respond({ body });
}

two changes needed:

  1. serve() needs to take { port: 8000 } instead of ":8000".
  2. s.url to return "http://localhost:8000/"
good first issue

Most helpful comment

Why would s.url not return an instance of URL, which can be easily converted to a string, or otherwise used as seen fit?

All 6 comments

That's my luck 馃槃 an API change few days after I presented the old API in my last talk.
After my first talk got recorded but before it got published, the deno run outdated my examples.
Both very good changes by the way 馃憤 it's just funny how my talks get outdated in a matter of days.

Why would s.url not return an instance of URL, which can be easily converted to a string, or otherwise used as seen fit?

Is there a plain to change for-await-of to a concurrent API?

@Fenzland No - I'm happy with for-await-of API. It is concurrent (as long as you call an async function without await).

@ry I did a PR #3278 to implement this (and PR #3279 that is the same but uses URL objects instead of strings as suggested by @kitsonk so that console.log(s.url.href) would have to be used).

The CI currently fails on some systems, sorry for that, I'll have to see why it fails on some systems and not others.

currently (Deno v1.0.0) url in ServerRequest returns just the part after hostname (pathname and search-params)

I think there should be a property like href to get the whole url string or an instance of URL. (2nd point in issue)

This would make it easier to access different parts of the url, hostname, pathname, params e.t.c

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zugende picture zugende  路  3Comments

ry picture ry  路  3Comments

kitsonk picture kitsonk  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments

davidbarratt picture davidbarratt  路  3Comments