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;
})
Goals π
Examples π¨βπ
ECHO Server π
WebSockets π
Static files π
Mount Other Apps π
Request Models π¨βπ¬
Custom Path Param Types