Skip to content

NodeJS Bindings 🔥 #157

@Ethosa

Description

@Ethosa

Goals 📃

  • Make HappyX available for JS community;
  • Make fast HTTP framework for JS;
  • Make yet another SPA framework for JS (maybe in future).

Examples 👨‍🎓

ECHO Server 👋

import {Server} from "happyx";

// by default host and port is 127.0.0.1:5000 so you may to call it without args
let server = new Server("127.0.0.1", 5000);


server.get("/", (req) => {
  console.log(req);
  return "Hello, world!";
});


server.start()

WebSockets 🔌

server.ws("/sockets", (ws) => {
  console.log(ws.state);
  if (ws.state == WebSocketState.Open && ws.data == "ping") {
    ws.send("pong");
  }
});

Static files 📁

server.static("/route", "./directory")

Mount Other Apps 🛠

const main = new Server();
const users = new Server();

main.mount("/users", users);

// at http://127.0.0.1:5000/users/
users.get("/", () => {return 1});

Request Models 👨‍🔬

const UserModel = new RequestModel('UserModel', {
  username: ''
});

app.post('/[u:UserModel]', (req: Request) => {
  console.log(req.params.u.username)
});

Custom Path Param Types

newPathParamType("myType", /\d\d/, (data: string) => {
    return Number(data[0]) + Number(data[1]);
});

app.get("/test/custom/types{a:myType}", (req: Request) => {
    return req.params.a;
})

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions