Deno: Add HTTP server API

Created on 10 Sep 2018  路  11Comments  路  Source: denoland/deno

Example:

import * as deno from "deno";
const enc = new TextEncoder();
function handler(req: deno.HTTPRequest, res: deno.HTTPResponse) {
  let ab = enc.encode(`hello ${req.url.path}`);
  w.write(ab);
}
deno.httpServe(":8080", handler);

725 should be completed first.

Most helpful comment

@Janpot I'm starting on the http server now. I really like your idea of an inverse fetch. I probably won't do this for the first pass implementation - we need to get something simple working first - but I will explore it once we have some basic examples working.

Also: we need to support streaming bodies from fetch() (#522) before we can think about server inverse.

All 11 comments

http should implemented in js side instead of using hyper in rust side?

@sijad it should use hyper - we want to avoid reimplementing http

so why does #725 should be completed first?

@sijad because TCP is simpler and I anticipate more work will need to be done in the binding interface.

Probably not relevant anymore, but there were some ideas thrown around in https://github.com/denoland/deno/issues/199

@Janpot I'm starting on the http server now. I really like your idea of an inverse fetch. I probably won't do this for the first pass implementation - we need to get something simple working first - but I will explore it once we have some basic examples working.

Also: we need to support streaming bodies from fetch() (#522) before we can think about server inverse.

Love this project. I played around with it today and created simple http server library on top of the TCP-api. Is the plan still to add this API to deno or leave it for external libraries? Anyways, I ended up with this: (https://github.com/lenkan/deno-http). Let me know if it is something useful. If the plan is to use Hyper, I guess it's pretty irrelevant.

@ry I suppose line 5 of example was meant to be res.write(ab); ?

We have an http server API that working for several people in
https://github.com/denoland/deno_std/blob/2916791dfb14bf486185eca6c7859b49c1c4c052/net/http.ts
It is not very fast - but we have several larger performance refactors planned which we think may address that. Therefore closing this issue for now. If we can't make it fast enough, it may need to be implemented natively.

but we have several larger performance refactors planned

Are those documented anywhere?

Are those documented anywhere?

Unfortunately not well. I can try to write up some more but it鈥檚 partially here
https://github.com/denoland/deno/issues/1010

Was this page helpful?
0 / 5 - 0 ratings

Related issues

motss picture motss  路  3Comments

watilde picture watilde  路  3Comments

ry picture ry  路  3Comments

sh7dm picture sh7dm  路  3Comments

kyeotic picture kyeotic  路  3Comments