Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nhttp/nhttp
An Simple web-framework for Deno and Friends.
https://github.com/nhttp/nhttp
bun cloudflare-workers deno http-server nodejs
Last synced: 22 days ago
JSON representation
An Simple web-framework for Deno and Friends.
- Host: GitHub
- URL: https://github.com/nhttp/nhttp
- Owner: nhttp
- License: mit
- Created: 2021-05-29T08:41:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-12T07:38:21.000Z (5 months ago)
- Last Synced: 2024-10-01T03:41:56.576Z (about 1 month ago)
- Topics: bun, cloudflare-workers, deno, http-server, nodejs
- Language: TypeScript
- Homepage: https://nhttp.deno.dev
- Size: 1.16 MB
- Stars: 88
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
NHttp
An Simple web-framework for Deno and Friends.
[![CI](https://github.com/nhttp/nhttp/workflows/ci/badge.svg)](https://github.com/nhttp/nhttp)
[![JSR](https://jsr.io/badges/@nhttp/nhttp)](https://jsr.io/@nhttp/nhttp)
[![JSR_SCORE](https://jsr.io/badges/@nhttp/nhttp/score)](https://jsr.io/@nhttp/nhttp/score)
[![CODECOV](https://codecov.io/gh/nhttp/nhttp/branch/master/graph/badge.svg?token=SJ2NZQ0ZJG)](https://codecov.io/gh/nhttp/nhttp)
[![DENO](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fnhttp%2Fmod.ts)](https://deno.land/x/nhttp)
[![MIT](https://img.shields.io/:license-mit-blue.svg)](http://badges.mit-license.org)
[![PRS](https://img.shields.io/badge/PRs-welcome-blue.svg)](http://makeapullrequest.com)## Features
- Focus on simple and easy to use.
- Fast Performance.
[One of the fastest Frameworks](https://github.com/denosaurs/bench#hello-bench).
- 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](https://github.com/nhttp/nhttp/tree/master/examples)
## Installation
### JSR
```bash
// 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
```ts
import nhttp from "https://deno.land/x/nhttp/mod.ts";
```## Simple Usage
Create file `app.ts` and copy-paste this code.
```ts
import nhttp from "@nhttp/nhttp";const app = nhttp();
app.get("/", () => {
return "Hello, World";
});app.get("/cat", () => {
return { name: "cat" };
});app.listen(8000);
```### Run
```bash
deno run -A app.ts
```## Using JSX + Htmx
Create file `app.tsx` and copy-paste this code.
```jsx
import nhttp from "@nhttp/nhttp";
import { htmx, renderToHtml } from "@nhttp/nhttp/jsx";const app = nhttp();
app.engine(renderToHtml);
app.use(htmx());
app.get("/", () => {
return (
Click Me
);
});app.post("/clicked", () => {
return It's Me;
});app.listen(8000);
```## config jsx
deno.json / tsconfig.json
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "@nhttp/nhttp/jsx"
}
}
```more docs => https://nhttp.deno.dev
## Standard Lib
Like `std-libs` for NHttp.
### Usage
```ts
// JSR
import {...} from "@nhttp/nhttp/my-libs";// deno.land
import {...} from "https://deno.land/x/nhttp/lib/my-libs.ts";
```### Serve Static
```ts
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
```bash
deno run -Ar npm:create-nhttp
```### Npm
```bash
npm create nhttp@latest
```## License
[MIT](LICENSE)