NHttp
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).
- Return directly on handlers.
- No third party modules and no std/lib by default.
- Easy deploy to Deno Deploy and Cloudflare Workers.
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.
for cloudflare workers visit => https://nhttp.deno.dev/docs/usage/cloudflare-workers
Installation
deno.land
import { NHttp } from "https://deno.land/x/nhttp@0.8.5/mod.ts";
nest.land
import { NHttp } from "https://x.nest.land/nhttp@0.8.5/mod.ts";
Usage
import { NHttp } from "https://deno.land/x/nhttp@0.8.5/mod.ts";
const app = new NHttp();
app.get("/", ({ response }) => {
return response.send("Hello");
});
app.get("/json", ({ response }) => {
return response.json({ name: "nhttp" });
});
// Return directly
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
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