Crate gleif_rs

Source
Expand description

§GLEIF API Client Library (gleif_rs)

This Rust library provides a type-safe, ergonomic client for interacting with the Global Legal Entity Identifier Foundation (GLEIF) API. Whether you’re retrieving LEI records, filtering data, or managing API responses, this library ensures seamless integration with strong typing and clear error handling.

§Features

§Getting Started

Run the following Cargo command in your project directory:

cargo add gleif-rs

§Basic Example: Fetching an LEI Record

The following example demonstrates how to fetch a specific LEI record using its ID.

use gleif_rs::{
    client::GleifClient,
    error::GleifError,
    model::LeiRecord,
};

#[tokio::main]
async fn main() -> Result<(), GleifError> {
    // Initialize the GLEIF client
    let client = GleifClient::new();
    // Fetch a specific LEI record by its ID
    let lei_record: LeiRecord = client.lei_record_by_id("5493001KJTIIGC8Y1R12").await?;

    println!("LEI Record: {lei_record:#?}");
    Ok(())
}

§Filtering LEI Records

You can refine your API queries using filters:

use gleif_rs::{
    client::GleifClient,
    error::GleifError,
    field::Field,
    model::LeiRecordList,
    value::{EntityCategory, RegistrationStatus},
};

#[tokio::main]
async fn main() -> Result<(), GleifError> {
    // Initialize the GLEIF client
    let client = GleifClient::new();
    // Fetch LEI records with specific filters
    let lei_records: LeiRecordList = client
        .lei_records()
        .filter_eq(Field::EntityCategory, EntityCategory::Fund)
        .filter_eq(Field::RegistrationStatus, RegistrationStatus::Issued)
        .sort(Field::EntityLegalName)
        .page_size(10)
        .send()
        .await?;

    println!("Found {} matching records.", lei_records.data.len());
    Ok(())
}

§Advanced Configuration: Custom HTTP Client

For greater control over API requests, such as retry policies and timeouts, you can customize the underlying HTTP client:

use gleif_rs::client::GleifClient;
use reqwest::Client as ReqwestClient;
use reqwest_middleware::ClientBuilder;
use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff};
use std::time::Duration;

#[tokio::main]
async fn main() {
    let reqwest_client = ReqwestClient::builder()
        .timeout(Duration::from_secs(30))
        .connect_timeout(Duration::from_secs(5))
        .build()
        .expect("Failed to create reqwest client");
    let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
    let middleware = ClientBuilder::new(reqwest_client)
        .with(RetryTransientMiddleware::new_with_policy(retry_policy))
        .build();
    let client = GleifClient::from_middleware_client(middleware);
    println!("GLEIF client initialized with custom middleware: {}", client.base_url());
}

§Error Handling

All API methods return crate::error::Result. See the crate::error module for details.

§License

This project is licensed under the MIT License. See LICENSE for details.


Feel free to explore and extend its capabilities based on your needs!

Modules§

client
Main GLEIF API Client (GleifClient) - Entry Point for GLEIF API Interactions.
endpoint
GLEIF API Endpoints
error
Error Handling (GleifError) - Error types for API operations.
field
API Field Definitions (Field) - Type-Safe Enum of GLEIF API Field Names
model
Model definitions for the GLEIF API.
request_builder
GLEIF API Request Builder (GleifRequestBuilder) - Flexible and Fluent API Request Construction.
value
GLEIF API Field Value Enums (value) - Type-Safe Enums for GLEIF API Field values

Constants§

DEFAULT_BASE_URL
The default base URL for the GLEIF API v1.
VERSION
Library version