2个不稳定版本
使用旧的Rust 2015
0.2.0 | 2016年12月1日 |
---|---|
0.1.0 | 2016年12月1日 |
500 在 HTTP客户端
19KB
406 行
http_event_store
Rust HTTP连接器到 Event Store。
目前针对EventStore 3.x。
标签
Rust, 数据库, 事件存储, 事件溯源, CQRS, RESTful API, AtomPub
入门
来自 crates.io。
extern crate http_event_store;
extern crate serde_json;
extern crate uuid;
use http_event_store::client::Client;
use http_event_store::write::Event;
use http_event_store::read::BodyEntry;
use http_event_store::expected_version::ExpectedVersion;
fn main() {
let client = Client::default(); // 127.0.0.1:2113 by default
let event = Event {
event_id: uuid::Uuid::new_v4(),
event_type: "event-type".to_string(),
data: Some(serde_json::from_str(r#"{ "a": "1" }"#).unwrap())
};
client.append_to_stream("newstream", ExpectedVersion::NoStream, vec![event]).unwrap();
let stream = client.read_stream_events_forward::<BodyEntry>("newstream", 0, 100, true).unwrap();
println!("Stream entry: {:?}", stream.entries[0]);
}
主要公共API类型
client::Client
- API客户端write::Event
- 事件结构体(写入端)read::Stream<E>
- 事件流(读取端)read::BodyEntry
- 流条目(读取端)error::ApiError
- API错误
API函数
append_to_stream
cURL: curl -i -d @simple-event.txt -H "Content-Type:application/vnd.eventstore.events+json" "http://127.0.0.1:2113/streams/newstream"
Rust: client.append_to_stream("newstream", ExpectedVersion::NoStream, vec![simple_event]);
read_stream_events_forward
cURL: curl -i -H "Accept:application/vnd.eventstore.atom+json" "http://127.0.0.1:2113/streams/newstream"
Rust: let result = client.read_stream_events_forward::<NoneEntry>("newstream", 0, 100, true, true);
将数据嵌入流中
读取流有两种选项:嵌入完整的事件或仅提供实际事件数据的链接。比较
let stream_with_data = client.read_stream_events_forward::<BodyEntry>("newstream", 0, 100, true).unwrap();
let stream_with_links = client.read_stream_events_forward::<NoneEntry>("newstream", 0, 100, true).unwrap();
查看tests/test_read_stream_events_forward.rs
和src/lib.rs.in
以获取详细信息。
delete_stream
cURL: curl -v -X DELETE http://127.0.0.1:2113/streams/foo
Rust: client.delete_stream("foo", ExpectedVersion::<Any>);
hard_delete_stream
cURL: curl -v -X DELETE http://127.0.0.1:2113/streams/foo2
Rust: client.hard_delete_stream("foo", ExpectedVersion::<Any>);
开发环境
$ uname -a
Linux blah 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ rustc --version
rustc 1.13.0 (2c6933acc 2016-11-07)
许可证
MIT
依赖项
~8.5MB
~177K SLoC