Skip to content

layer78/http-native

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Http-native

Http native is a express like server framework for Javascript that uses the Node-compatible framework with Rust native module way, where the rust binary is evoked through napi-rs or something faster.

You can also import the default server tuning config and override it before listen():

import httpServerConfig from "http-native/http-server.config";

Rust handler (http) <-> (javascript logic)

The rust server handles all the http, while the core javascript logic is run sperately (EXREMELY fast)

Extrat performance features:

1) Ahead of time constant data indentification. (If the data in the route's logic isn't manipulated at runtime we directly store it in rust so we don't envoke the javascript logic)

2) Faster than bun.server() aswell as fastify.

3) Default async handling (Yes rust handles the async for you.)

So start by just writing

import { createApp } from "../src/index.js";

const db = {
  async getUser(id) {
    return {
      id,
      name: "Ada Lovelace",
      role: "admin",
    };
  },
};

const app = createApp();

app.use(async (req, res, next) => {
  res.header("x-powered-by", "http-native");
  await next();
});

app.get("/", (req, res) => {
  res.json({
    ok: true,
    engine: "rust",
    bridge: "napi-rs",
  });
});

app.get("/users/:id", async (req, res) => {
  const user = await db.getUser(req.params.id);
  res.json(user);
});

const server = await app.listen({
  port: 3001,
  serverConfig: {
    ...httpServerConfig,
    maxHeaderBytes: 32 * 1024,
  },
});

Runtime optimization reporting:

console.log(server.optimizations.summary());
console.log(server.optimizations.snapshot());

Pass opt: { notify: true } to listen() if you want runtime logs when a route is already native static or looks stable enough to cache later.

This should outperform the OLD shit code (found in old/), and be 50% faster than bun.server(), write tests in test.js plus add benchmarks so we know its faster than bun.

Remeber nadhi u moron this will be a library so don't go around doing shit.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 57.6%
  • Rust 42.4%