Crates.io | http_event_store |
lib.rs | http_event_store |
version | 0.2.0 |
source | src |
created_at | 2016-12-01 18:48:38.359753 |
updated_at | 2016-12-01 20:35:58.013025 |
description | Greg's Event Store Rust HTTP Client |
homepage | |
repository | https://github.com/MitinPavel/http_event_store |
max_upload_size | |
id | 7430 |
size | 33,748 |
Rust HTTP connector to Event Store.
Is currently targeting EventStore 3.x.
Rust, Database, Event Store, Event Sourcing, CQRS, RESTful API, AtomPub
Available from 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]);
}
client::Client
- API clientwrite::Event
- Event struct (write side)read::Stream<E>
- Stream of events (read side)read::BodyEntry
- Stream entry (read side)error::ApiError
- API errorcURL: 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]);
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);
There are two options reading streams: embed full fledged events or just provide links to actual event data. Compare:
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();
Check tests/test_read_stream_events_forward.rs
and src/lib.rs.in
for details.
cURL: curl -v -X DELETE http://127.0.0.1:2113/streams/foo
Rust: client.delete_stream("foo", ExpectedVersion::Any);
cURL: curl -v -X DELETE http://127.0.0.1:2113/streams/foo2 -H "ES-HardDelete:true"
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