Skip to main content

Built and signed on GitHub Actions

An Simple web-framework for deno and friends.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
10 months ago (2.0.2)

logo

NHttp

An Simple web-framework for Deno and Friends.


CI JSR JSR_SCORE CODECOV DENO MIT PRS

Features

  • Focus on simple and easy to use.
  • Fast Performance. One of the fastest Frameworks.
  • Cross runtime support (Deno, Node, Bun, etc).
  • Low overhead & True handlers (no caching anything).
  • Built-in Middleware.
  • Sub router support.
  • Template engine support (jsx, ejs, nunjucks, eta, pug, ..etc).
  • Return directly on handlers.
  • Auto parses the body (json / urlencoded / multipart / raw).

See Examples

Installation

JSR

// Deno
deno add @nhttp/nhttp

// npm
npx jsr add @nhttp/nhttp

// Yarn
yarn dlx jsr add @nhttp/nhttp

// pnpm
pnpm dlx jsr add @nhttp/nhttp

// Bun
bunx jsr add @nhttp/nhttp

deno.land

import nhttp from "https://deno.land/x/nhttp/mod.ts";

Simple Usage

Create file app.ts and copy-paste this code.

import nhttp from "@nhttp/nhttp";

const app = nhttp();

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

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

app.listen(8000);

Run

deno run -A app.ts

Using JSX + Htmx

Create file app.tsx and copy-paste this code.

import nhttp from "@nhttp/nhttp";
import { htmx, renderToHtml } from "@nhttp/nhttp/jsx";

const app = nhttp();

app.engine(renderToHtml);

app.use(htmx());

app.get("/", () => {
  return (
    <button hx-post="/clicked" hx-swap="outerHTML">
      Click Me
    </button>
  );
});

app.post("/clicked", () => {
  return <span>It's Me</span>;
});

app.listen(8000);

config jsx

deno.json / tsconfig.json

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@nhttp/nhttp/jsx"
  }
}

more docs => https://nhttp.deno.dev

Standard Lib

Like std-libs for NHttp.

Usage

// JSR
import {...} from "@nhttp/nhttp/my-libs";

// deno.land
import {...} from "https://deno.land/x/nhttp/lib/my-libs.ts";

Serve Static

import nhttp from "@nhttp/nhttp";
import serveStatic from "@nhttp/nhttp/serve-static";

const app = nhttp();

app.use(serveStatic("./my_folder"));

// with prefix
app.use(serveStatic("./my_folder", { prefix: "/assets" }));
// or
// app.use("/assets", serveStatic("./my_folder"));

// with URL
app.use(serveStatic(new URL("./my_folder", import.meta.url)));

CLI

Deno

deno run -Ar npm:create-nhttp

Npm

npm create nhttp@latest

License

MIT

Examples

Example 1

import nhttp from "@nhttp/nhttp";

const app = nhttp();

app.get("/", (rev) => {
  return "hello world";
});

app.listen(8000);
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@nhttp/nhttp

Import symbol

import * as nhttp from "@nhttp/nhttp";

---- OR ----

Import directly with a jsr specifier

import * as nhttp from "jsr:@nhttp/nhttp";

Add Package

npx jsr add @nhttp/nhttp

Import symbol

import * as nhttp from "@nhttp/nhttp";

Add Package

yarn dlx jsr add @nhttp/nhttp

Import symbol

import * as nhttp from "@nhttp/nhttp";

Add Package

pnpm dlx jsr add @nhttp/nhttp

Import symbol

import * as nhttp from "@nhttp/nhttp";

Add Package

bunx jsr add @nhttp/nhttp

Import symbol

import * as nhttp from "@nhttp/nhttp";