
🔍
http.o
Helps to create a simple HTTP server.
Elements are used to start the server
| Name | Description / comments |
|---|---|
| .http.default.bind | Get default / set string with binding ip:port |
| .http.default.host | Get default / set string with user name |
| .http.default.home | Get default / set string with current dir |
| .http.default.handle[<sock>;<headers>] | Request handler function - receives socket and headers dictionary, must send response |
| .http.run[<creds>] | Start http server |
Example:
Basic HTTP server:
o)load[getenv[`OHOME];"http"];
o)
o)// Configure server
o).http.default.bind: "127.0.0.1:8080";
o).http.default.host: "MyServer";
o).http.default.home: getenv[`HOME];
o)
o)// Define request handler
o).http.default.handle: {[sock;headers]
path: "c"$headers[`Path];
if [path~"/hello"] {
body: "Hello from The Platform!
";
.http.resp.ok[sock;`html;body];
} elif [path~"/"] {
body: "Welcome
Server is running
";
.http.resp.ok[sock;`html;body];
} else {
.http.resp.error[sock;404;"Not found";"Page does not exist"];
}
};
o)
o)// Start server (requires -c 0 flag: tachyon -c 0 -f script.o)
o).http.run[];
---
HTTP server version: 1.0.4
Started: 2026.03.26D01:30:00.000000000
Bind: 127.0.0.1:8080
Hostname: MyServer
Parse URL:
o).http.url.parse["http://localhost:8080/test.html?id=123"]
Path | http://localhost:8080/test.html
Query| id=123
Send responses:
o)// In request handler:
o)// Success with HTML
o).http.resp.ok[sock;`html;"OK
"];
o)
o)// Success with JSON
o).http.resp.ok[sock;`json;"{\"status\":\"ok\"}"];
o)
o)// Error response
o).http.resp.error[sock;404;"Not Found";"The requested page does not exist"];
o)
o)// Custom response
o).http.resp.send[sock;.http.const.code`ok;.http.const.mime`html;"Custom
"];
Auxiliary elements
| Name | Description / comments |
|---|---|
| .http.const.version[] | Version string |
| .http.const.error | Template string of error with 3 % |
| .http.const.code | Dictionary with supported error codes |
| .http.const.mime | Dictionary with supported mime |
| .http.const.head | Template string of head page with 4 % |
| .http.const.temp | Template string of html page with 2 % for title and body |
| .http.buffer.handle | Return the lambdas which processing socket |
| .http.url.parse[<url>] | Parse URL to dictionary |
| .http.req.parse[<req>] | Request parse to dictionary |
| .http.resp.error[<sock>;<code>;<payload>;<explanation>] | Response error |
| .http.resp.ok[<sock>;<mime>;<payload>] | Response OK |
| .http.resp.send[<sock>;<code>;<mime>;<payload>] | Send response |
| .http.serve[<bind>;<handle>;<creds>] | Start http server |