16 个版本
使用旧的 Rust 2015
0.2.3 | 2017 年 9 月 1 日 |
---|---|
0.2.1 | 2017 年 8 月 31 日 |
0.2.0 | 2017 年 6 月 15 日 |
0.1.12 | 2017 年 4 月 24 日 |
0.1.5 | 2017 年 1 月 6 日 |
在 HTTP 服务器 中排名 1006
每月下载量 35 次
2.5MB
773 行
Rusqbin

Rusqbin 是一个 Web 服务器,用于存储您的请求以供以后检索。它可以通过 crates.io 作为 Docker 图像、二进制文件和库使用。
Rusdocs 已发布于
使用方法
Web API
Web 服务器有以下 API 用于处理请求存储。
POST
/rusqbins 创建一个存储并返回 bin_idGET
/rusqbins 列出存储摘要GET
/rusqbins/${bin_id} 获取特定存储的摘要信息GET
/rusqbins/${bin_id}/requests 获取存储的详细请求信息(列出存储中的所有请求)DELETE
/rusqbins/${bin_id} 删除存储
在任何其他情况下,通过带有 bin_id 的 X-Rusqbin-Id 标头的请求进行请求,以将您的请求记录到存储中以便以后检索。
Docker
$docker run lloydmeta/rusqbin:latest
二进制文件
要使用 Rusqbin 作为二进制文件,只需使用 cargo install rusqbin
安装它,然后运行 rusqbin
,并遵循简单的使用说明。可以通过添加端口号参数来设置服务器运行的端口号。
日志记录由 env_logger
处理,因此您可以使用 RUST_LOG
环境变量在运行时进行配置。
库
要将其作为库使用,将其添加到项目中作为 crate 依赖项,然后在 Rust 代码中
use rusqbin::storage::*;
use rusqbin::server::*;
use rusqbin::models::*;
use hyper::{Method, Uri};
use hyper::client::Client;
use hyper::client::Request as HyperRequest;
use std::io::Read;
use std::thread;
use std::sync::{Arc, Mutex};
use std::str::FromStr;
use futures::future;
// Start a BinsServer on port 7000 in another thread, utilising
// a simple mutex for shutting it down. A channel could also work.
let server = Arc::new(BinsServer::new(7000, InMemoryBins::new()));
let arc_stay_alive = Arc::new(Mutex::new(true));
let bg_server = server.clone();
let bg_stay_alive = arc_stay_alive.clone();
thread::spawn(move || {
bg_server.run_until(future::poll_fn(|| {
if *bg_stay_alive.lock().unwrap() {
Ok(futures::Async::NotReady)
} else {
Ok(futures::Async::Ready(()))
}
}))
});
let mut client_core = tokio_core::reactor::Core::new().unwrap();
let client = Client::new(&client_core.handle());
// Create a bin via programmatically, making sure to scope the
// storage unlocking with braces properly
let bin = {
let mut server_storage = server.storage.lock().unwrap();
server_storage.create_bin()
};
let bin_id = bin.id.value();
// Fire an HTTP request with the proper X-Rusqbin-Id header
let mut req = HyperRequest::new(Method::Post, Uri::from_str("https://127.0.0.1:7000/hello/world").unwrap());
req.headers_mut().set(XRusqBinId(bin_id.to_owned()));
let future_resp = client.request(req);
// Here we use core.run to block on response, but you should never
// do this in production code.
client_core.run(future_resp);
// Check to make sure our HTTP request was received and stashed
// in our rusqbin server
{
let mut server_storage = server.storage.lock().unwrap();
let bin_requests: &Bin = server_storage.get_bin(&bin.id).unwrap();
let req = &bin_requests[0];
assert_eq!(req.method, "POST".to_owned());
assert_eq!(req.path, "/hello/world".to_owned());
}
// Cleanup by shutting down our server using the mutex
*arc_stay_alive.lock().unwrap() = false;
在上面的示例中,我们使用现成的InMemoryBins
进行存储,但在创建BinsServer时,您也可以传递任何给定的rusqbin::storage::Bins
实现。
版权
Rusqbin是使用Rust编写的Requestbin的一个简单端口。受到Requestinator的启发。
依赖项
~17MB
~322K SLoC