nhttp

An Simple web-framework for Deno and Friends.

MIT License

Downloads
4.4K
Stars
88
Committers
7

Bot releases are hidden (Show)

nhttp - 1.2.13

Published by herudi over 1 year ago

  • Deno.serve requires --unstable.
  • (Internals) build_npm.
  • (Internals) deno.json remove files for fmt and lint.
nhttp - 1.2.12

Published by herudi over 1 year ago

  • remove overload Deno.serve
nhttp - 1.2.11

Published by herudi over 1 year ago

New Feature

  • Now, serve-static support SPA (single page app). set spa to true via options.
nhttp - 1.2.10

Published by herudi over 1 year ago

New Features

@Jwt Decorator

import { Jwt } from "https://deno.land/x/[email protected]/lib/jwt.ts";

@Controller("/admin")
class AdminController {
  ...
  @Jwt("secret")
  @Get("/home")
  home(rev: RequestEvent) {
    console.log("Payload =>", rev.auth);
    return "Welcome Home";
  }
  ...
}

// http://localhost:8000/admin/home
// Authorization = Bearer <token>
nhttp - 1.2.9

Published by herudi over 1 year ago

New Libs

jwt

import jwt from "https://deno.land/x/[email protected]/lib/jwt.ts";

const JWT_SECRET = "myjwtsecret";

app.post("/login", validate(LoginSchema), (rev) => {
  // example payload.
  const payload = {
    iat: Math.round(Date.now() / 1000),
    // expires 1 hours
    exp: Math.round(Date.now() / 1000 + (1 * 60 * 60)),
    user: rev.body.username,
  };
  return { token: jwt.encode(payload, JWT_SECRET) };
});

app.get("/admin/home", jwt(JWT_SECRET), (rev) => {
  return `Welcome ${rev.auth.user}`;
});
nhttp - 1.2.8

Published by herudi over 1 year ago

New Feature

  • (Node) Custom Inspect RequestEvent and HttpResponse.
  • (Node) serveNode for custom server.
import { serveNode } from "nhttp-land";

serveNode(() => new Response("hello node"), { port: 8000 });
nhttp - 1.2.7

Published by herudi over 1 year ago

New Lib

zod-validator

import nhttp from "https://deno.land/x/[email protected]/mod.ts";
import validate, { z } from "https://deno.land/x/[email protected]/lib/zod-validator.ts";

const User = z.object({
  username: z.string(),
  password: z.string(),
  user_info: z.object({
    name: z.string(),
    address: z.string(),
  }),
});

const app = nhttp();

// support all content-type (json, multipart, raw, urlencoded)
app.post("/", validate(User), (rev) => {
  return rev.body.user_info;
});

app.listen(8000, (_err, info) => {
  console.log(`Running on port ${info.port}`);
});

tRPC

see examples

nhttp - 1.2.6

Published by herudi over 1 year ago

Minor feature

  • expose h for jsx
nhttp - 1.2.5

Published by herudi over 1 year ago

  • fix JSX array child
nhttp - 1.2.4

Published by herudi over 1 year ago

  • Add types for commonjs (Nodejs)
nhttp - 1.2.3

Published by herudi over 1 year ago

serve-static only GET/HEAD

nhttp - 1.2.2

Published by herudi over 1 year ago

New

default import

import nhttp from "https://deno.land/x/[email protected]/mod.ts";

// or still supported
import { nhttp } from "https://deno.land/x/[email protected]/mod.ts";
nhttp - 1.2.1

Published by herudi over 1 year ago

Directly jsx

nhttp - 1.2.0

Published by herudi over 1 year ago

New Feature

Jsx

Simple jsx libs with Helmet for SEO.

/** @jsx n */
/** @jsxFrag n.Fragment */

import { n, Helmet, renderToHtml, FC } from "https://deno.land/x/[email protected]/lib/jsx.ts";
import { nhttp } from "https://deno.land/x/[email protected]/mod.ts";

const Home: FC<{ title: string }> = (props) => {
  return (
    <>
      <Helmet>
        <title>{props.title}</title>
      </Helmet>
      <h1>Home Page</h1>
    </>
  );
};

const app = nhttp();

app.engine(renderToHtml);

app.get("/", () => <Home title="welcome jsx" />);

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

Expected in browser

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>welcome jsx</title>
  </head>
  <body>
    <h1>Home Page</h1>
  </body>
</html>

Inline bodyParser (validation)

app.post("/", bodyParser({ json: "5kb" }), ({ body }) => body);
nhttp - 1.1.20

Published by herudi over 1 year ago

  • Partly NPM
  • serve_static path
nhttp - 1.1.19

Published by herudi over 1 year ago

New Features:

  • ServeStatic accept-range
  • Response and Request Web API for Nodejs with same performance with native node:http(s)
nhttp - 1.1.18

Published by herudi over 1 year ago

partly

nhttp - 1.1.17

Published by herudi over 1 year ago

Features

ServeStatic now support Deno, Bun, Node.

import { serveStatic } from "nhttp-land/serve-static";

const app = nhttp();

app.use(serveStatic("dir"));

multipart.upload now support Deno, Bun, Node.

import { multipart, nhttp } from "nhttp-land";

const app = nhttp();

const upload = multipart.upload({ name: "image" });

app.post("/upload", upload, (rev) => {
  console.log(rev.file);
  console.log(rev.body);
  return "Success Upload";
})
nhttp - 1.1.16

Published by herudi over 1 year ago

New Features

  • ServeStatic
nhttp - 1.1.15

Published by herudi over 1 year ago

Features

  • add schemas to class-validator.