Lucia

CI crates.io Documentation License Rustc

A flexible client API framework for writing asynchronous, fast, maintainable and scalable applications with the Rust programming language. Supports several data formats, transports and custom parameters.

Checkout the lucia-apis project to see a collection of APIs based on lucia.

Infrastructure

A structure that implements the Package trait describes request data as well as any other additional parameters like HTTP header values.

Auxiliary elements attached to the instance of an API like byte buffers or throttling parameters are declared in a separate mandatory entity called PackagesAux, which is responsible for assisting the creation and management of packages and their requests.

Take a look at the following example using lucia_macros to create a JSON-RPC request with fluent interfaces, reqwest to send data and serde_json to decode the returned bytes from the server.

```rust,ignore use lucia::{dnsn::SerdeJson, network::{transport::Transport, HttpParams}};

lucia::createpackagesaux_wrapper!();

[derive(Debug)]

pub struct MyApi;

type MyApiPackagesAux = PackagesAux;

[lucia::pkg(api(super::MyApi), dataformat(jsonrpc("my_endpoint")), transport(http))]

mod my_endpoint { #[pkg::aux] impl super::MyApiPackagesAux {}

#[derive(Debug, serde::Serialize)] #[pkg::req_data] pub struct MyEndpointReqData<'any> { pub foo: i64, pub bar: &'any str, }

#[derive(Debug, serde::Deserialize)] #[pkg::res_data] pub struct MyEndpointResData { pub data: i32, } }

pub async fn fetchmyendpoint() -> lucia::Result { let pkgsaux = &mut MyApiPackagesAux::fromminimum( MyApi, SerdeJson, HttpParams::fromurl("https://www.someurl.com/api/v1")?, );

let pkg = &mut pkgsaux.myendpoint().data(123, "321").build();

let trans = &mut reqwest::Client::new();

Ok(trans.sendretrieveanddecodecontained(pkg, pkgs_aux).await?.result?.data) } ```

Data formats

| Name | URL | |---|---| | JSON | https://www.json.org/json-en.html | | JSON-RPC 2.0 | https://www.jsonrpc.org/ | | XML | https://www.w3.org/TR/xml/ | | YAML | https://yaml.org/spec/ |

De-serializers/Serializers

| Feature | URL | |---|---| | miniserde | https://docs.rs/miniserde | | serde_json | https://docs.rs/serde_json | | serde-xml-rs | https://docs.rs/serde-xml-rs | | serde-yaml | https://docs.rs/serde_yaml |

Transports

| Name | Feature | URL | |---|---|---| | Reqwest | reqwest | https://docs.rs/reqwest | | Surf | surf | https://docs.rs/surf | | TcpStream | std | https://doc.rust-lang.org/std/net/struct.TcpStream.html | | tokio-tungstenite | tokio-tungstenite |https://docs.rs/tokio-tungstenite | | UdpStream | std | https://doc.rust-lang.org/std/net/struct.UdpSocket.html |