Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeJS Bindings πŸ”₯ #157

Open
Ethosa opened this issue Oct 4, 2023 · 4 comments
Open

NodeJS Bindings πŸ”₯ #157

Ethosa opened this issue Oct 4, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request language bindings

Comments

@Ethosa
Copy link
Contributor

Ethosa commented Oct 4, 2023

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;
})
@Ethosa Ethosa added enhancement New feature or request language bindings labels Oct 4, 2023
@Ethosa Ethosa pinned this issue Oct 4, 2023
Ethosa added a commit that referenced this issue Oct 6, 2023
@Ethosa
Copy link
Contributor Author

Ethosa commented Oct 7, 2023

Now with hpx CLI you can create JavaScript/TypeScript projects

@georgelemon
Copy link

This is great! I'm curious about numbers, any benchmarks?

@Ethosa
Copy link
Contributor Author

Ethosa commented Oct 8, 2023

@georgelemon I'm try to open the-benchmarker/web-frameworks#6798 but server doesn't want to start πŸ€”

@waghanza
Copy link

Results are out https://web-frameworks-benchmark.netlify.app/result?f=happyx but not very satisfying (internal issues on this benchmarking project)

@Ethosa Ethosa unpinned this issue Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language bindings
Projects
None yet
Development

No branches or pull requests

4 participants