4 releases

0.1.3 Jan 19, 2022
0.1.2 Jan 5, 2022
0.1.1 Jan 3, 2022
0.1.0 Nov 10, 2021

#6 in #exchange-rate

Download history 15/week @ 2024-07-26 5/week @ 2024-08-02 2/week @ 2024-08-30 5/week @ 2024-09-06 4/week @ 2024-09-13 26/week @ 2024-09-20 14/week @ 2024-09-27 8/week @ 2024-10-04 27/week @ 2024-10-11 23/week @ 2024-10-18 5/week @ 2024-10-25 4/week @ 2024-11-01

61 downloads per month

MIT/Apache

33KB
740 lines

abstractapi-rs

GitHub Workflow Status Crates.io docs.rs Codecov

Rust API bindings for the Abstract HTTP API.

APIs

abstractapi-rs is compatible with v1 versions of the following API's that Abstract provides:

Usage

Add abstractapi to dependencies in your Cargo.toml:

[dependencies]
abstractapi = "0.1.*"

Getting Started

In order to interact with the APIs, you need to create a client (AbstractApi) first:

let mut abstractapi = abstractapi::AbstractApi::default();

Then you should set an API key specific for the API you would like to use. Here is an example for Geolocation API:

abstractapi.set_api_key(abstractapi::ApiType::Geolocation, "<api_key>").unwrap();

See ApiType enum for currently supported APIs.

The next step would be calling the function related to the API you want to use:

let geolocation: abstractapi::api::Geolocation = abstractapi.get_geolocation("172.217.19.142").unwrap();

Function parameters and return values (Structs) are directly mapped from the official API documentation so you may frequently need to refer to it for the meaning of these fields.

Tips

  • You can use the prelude module for glob-importing the common types.
  • There are alternative constructor methods available for creating a client with API keys. (e.g. new_with_api_keys)

Here is a full example that shows the basic usage of phone validation API:

use abstractapi::prelude::*;

fn main() -> Result<(), AbstractApiError> {
    // Create a new Abstract API client for phone validation.
    let abstractapi = AbstractApi::new_with_api_key(
        ApiType::PhoneValidation,
        std::env::var("PHONE_VALIDATION_API_KEY").unwrap(),
    )?;

    // Get the phone number details.
    let phone_details: PhoneDetails = abstractapi.validate_phone("14152007986")?;

    // Print the result.
    println!("{:#?}", phone_details);

    Ok(())
}

Examples

Look through the examples folder to see how the library can be used for integrating different APIs.

Contributing

Pull requests are welcome!

License

All code is dual-licensed under The MIT License and Apache 2.0 License.

Dependencies

~5.5–8MB
~142K SLoC