Skip to content
🌾A progressive http server / router for deno🌾
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
benchmark
fixtures
.editorconfig
.gitignore
.licenserc.json
.travis.yml
LICENSE
Makefile
README.md
make.sh
promises.ts
readers.ts
readers_test.ts
responder.ts
responder_test.ts
router.ts
router_test.ts
serveio.ts
serveio_test.ts
server.ts
server_test.ts
tests.ts

README.md

servest

https://travis-ci.org/keroxp/servest.svg?branch=master

🌾A progressive http server / router for deno🌾

Usage

Serve API

serve API is compatible to deno_std@v0.3.2 but has different implementation. Some progressive features for HTTP/1.1 server are implemented.

  • Support Keep-Alive connection
  • Support trailer headers
  • Support keep-alive timeout and read timeout
  • serve is cancellable by cancel promise
  • Fully interface based type definition
import { serve } from "https://denopkg.com/keroxp/servest@v0.4.0/server.ts";
async function main() {
  for await (const req of serve(`0.0.0.0:8899`)) {
    await req.respond({
      status: 200,
      headers: new Headers({
        "Content-Type": "text/plain"
      }),
      body: new TextEncoder().encode("hello")
    });
  }
}
main();

Router API

Router API is minimal routing system on top of serve()

import { createRouter } from "https://denopkg.com/keroxp/servest@v0.4.0/router.ts";

const router = createRouter();
router.handle("/", async req => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain"
    }),
    body: new TextEncoder().encode("ok")
  });
});
router.handle(new RegExp("/foo/(?<id>.+)"), async req => {
  const { id } = req.match.groups;
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "application/json"
    }),
    body: new TextEncoder().encode(JSON.stringify({ id }))
  });
});
router.listen("127.0.0.1:8898");

Loadmaps

  • Requester API
  • Middleware API for Router
  • HTTP/2

License

MIT

Contributor

@keroxp

You can’t perform that action at this time.