7个版本
0.3.1 | 2024年3月5日 |
---|---|
0.3.0 |
|
0.2.4 | 2024年3月4日 |
0.2.3 | 2023年12月10日 |
0.1.0 | 2023年12月9日 |
#375 in HTTP服务器
每月 347次下载
48KB
1K SLoC
简易HTTP脚本
概述
在运行时定义路由并执行与每个路由相关的脚本。服务器支持获取数据,用于代理目的。
用法
// the index route
index {
text(":3\nwelcome to the root")
}
// this is /hello
hello() {
text("Hello World!")
}
// get data from another website, then return as json
tests/fetch() {
json(http::get("https://httpbin.org/json").json())
}
// route placeholders
#[route("/example/{id}")]
example(id) {
text("base: " + id)
}
有关更多语法,请参阅 app.routes
# Start the server
script start <filename>
有关更多命令,请参阅 script --help
安装
Linux、MacOS和Windows的预构建二进制文件可在版本页面找到。
使用 cargo install script
从 crates.io 安装。
构建
- 克隆项目
- 在项目文件夹中打开终端
- 检查是否已安装 cargo (Rust 的包管理器),只需键入
cargo
- 如果已安装 cargo,运行
cargo build --release
- 将可执行文件放入您的 PATH 项之一,通常是
/bin/
或/usr/bin/
依赖关系
~41–56MB
~1M SLoC