-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
Description
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;
})Reactions are currently unavailable