Skip to main content

NHttp

License deno.land PRs Welcome deps badge cache badge nest.land

Fast native http framework for Deno, Deno Deploy and Cloudflare Workers.

Note: Deno native HTTP/2 Hyper requires Deno version 1.9.0 or higher.

Features

  • HTTP/2 support.
  • Middleware support.
  • Router support.
  • Includes body parser (jsonBody, urlencodedBody, rawBody, multipartBody).
  • Directly returning handlers.
  • No third party modules and no std/lib by default.
  • Easy deploy to Deno Deploy and Cloudflare Workers.

See examples

Benchmark

Here the simple benchmark.

autocannon -c 100 http://localhost:3000/hello

Name Req/sec Throughput
Native 21433 2.5 MB
NHttp 21127 2.5 MB
std/http 14569 626 KB

Note: maybe not relevant if compared with std/http or other Deno framework using std/http. nhttp uses native deno http.

Installation

deno.land

import { NHttp } from "https://deno.land/x/nhttp@0.8.0/mod.ts";

nest.land

import { NHttp } from "https://x.nest.land/nhttp@0.8.0/mod.ts";

Usage

import { NHttp } from "https://deno.land/x/nhttp@0.8.0/mod.ts";

const app = new NHttp();

app.get("/", ({ response }) => {
  response.send("Hello");
});

app.get("/json", ({ response }) => {
  response.json({ name: "nhttp" });
});

// Directly returning
app.get("/hello", () => {
  return "Hello World";
});

app.get("/hello/:name", ({ params }) => {
  return { name: params.name };
});

app.get("/nhttp", () => {
  return new Response("nhttp");
});

app.listen(3000, () => {
  console.log("> Running on port 3000");
});

Run

Note: Deno native http is unstable. so just add –unstable flag.

deno run --allow-net --allow-read --unstable yourfile.ts

Full Documentation NHttp

https://nhttp.deno.dev

or

https://nhttp.herudi.workers.dev

Want to contribute to this project? I gladly welcome it.

  • Please fork.
  • Create a branch.
  • Commit changes (before commit, please format the code with the command deno fmt in the src folder).
  • Push to the created branch.
  • Make a PR (Pull Requests).
  • Thanks.

List

  • Server App
  • Middleware
  • Router
  • Body Parser
  • Examples
  • Doc
  • Deno lint
  • Unit Test

License

MIT