feat(v1.5.0): Full-Stack Web Engine, F-Strings, Cyber OSINT & Terminal UI Suite
This commit is contained in:
1 parent
619492bdbf
commit
f90ea8cdd1
13 files changed
+766
-26
No files matched your search
@@ -0,0 +1,43 @@
|
||||
# 🌐 AiraLang Module: `serve`
|
||||
|
||||
The `serve` module provides a native, zero-dependency micro web server engine directly inside AiraLang. Build REST APIs, microservices, and webhook endpoints with minimal code.
|
||||
|
||||
---
|
||||
|
||||
## 📌 Functions
|
||||
|
||||
### 1. `serve.route(path, handler_fn, method="GET")`
|
||||
Registers a route endpoint. `handler_fn` receives a request dictionary containing `path`, `method`, `query`, `body`, and `headers`.
|
||||
```airalang
|
||||
import "serve";
|
||||
|
||||
serve.route("/api/hello", fn(req) {
|
||||
return {
|
||||
"status": "ok",
|
||||
"message": "Hello from AiraLang Web Engine!",
|
||||
"client_path": req["path"]
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
### 2. `serve.get(path, handler_fn)`
|
||||
Shortcut to register a `GET` route.
|
||||
```airalang
|
||||
serve.get("/api/status", fn(req) {
|
||||
return {"status": "online", "uptime": "100%"};
|
||||
});
|
||||
```
|
||||
|
||||
### 3. `serve.post(path, handler_fn)`
|
||||
Shortcut to register a `POST` route.
|
||||
```airalang
|
||||
serve.post("/api/echo", fn(req) {
|
||||
return {"received": req["body"]};
|
||||
});
|
||||
```
|
||||
|
||||
### 4. `serve.start(port=8080, host="0.0.0.0", background=false)`
|
||||
Starts the HTTP server. If `background=true`, the server runs in a daemon thread so the script can continue executing.
|
||||
```airalang
|
||||
serve.start(port=8080);
|
||||
```
|
||||
Reference in new issue
Block a user