Crates.io | lucid-client |
lib.rs | lucid-client |
version | 0.2.0 |
source | src |
created_at | 2020-05-09 18:29:34.463524 |
updated_at | 2020-05-10 13:08:03.924095 |
description | LucidKV DB Client based on Reqwest |
homepage | https://github.com/simoneromano96/lucid-client |
repository | https://github.com/simoneromano96/lucid-client |
max_upload_size | |
id | 239339 |
size | 5,633 |
LucidKV DB Client (Supports 0.14) based on Reqwest
For tests there must be a lucid db, you can use the preconfigured docker-compose/dockerfile.
I'll try to work on a Lucid image that support env variables, this will fix tests in CI and will help in other cases (that's the reason why the tests are failing on drone-ci).
Operations will be defined as an Enum to grant type safety.
Operations are:
Create a client:
Every operation will point to: base_url/api/kv/
so you just need to specify the host.
By default the base_url will be http://127.0.0.1:7020
// Without a base URL
let lucid_client_1 = LucidKVClient::new(None);
// With a base URL
let lucid_client_2 = LucidKVClient::new(Some("http://1.2.3.4:7020".into()));
Operations:
use serde_derive::{Serialize};
// Serializable data
#[derive(Serialize)]
struct DemoData {
demo: String,
}
// Demo data
let mut data = DemoData {
demo: "Something",
};
// Client instance
let lucid_client = LucidKVClient::new(None);
// Create
let res = lucid_client.store_data("key".into(), data).await?;
assert_eq!(res.status(), reqwest::StatusCode::OK);
// Read
let res = lucid_client.get_data("key".into()).await.unwrap();
assert_eq!(res.status(), reqwest::StatusCode::OK);
// Update
data = DemoData {
demo: "And now for something completely different",
}
let res = lucid_client.store_data("key".into(), data).await?;
assert_eq!(res.status(), reqwest::StatusCode::OK);
// Delete
// TODO
// Has key
// TODO
new
to create a new client, optionally specify a base_url
is_key_present
sends HEAD
request to lucidis_key_present
, this will return now a bool