Expand description

api-request-utils-rs

Crates.io Docs.rs

This library aims to provide a straightforward and efficient solution for making api requests It is designed to be user-friendly, customizable, and extensible, allowing developers to easily integrate and interact with APIs in their Rust applications.

Features

  • Convenient functions for sending HTTP requests and handling responses.
  • Error handling utilities for handling different types of request errors.
  • JSON serialization and deserialization helpers.
  • Parameter encoding and query string generation utilities.
  • Request builder and modifier traits for customization and extensibility.

Installation

Add the following line to your Cargo.toml file:

api-request-utils = "0.1.6"

To enable the export feature and include the specified dependencies (reqwest,serde_json, serde(with derive))

api-request-utils = { version = "0.1.6", features = ["export"]}

Usage

Import the required modules and types in your Rust code:

use api_request_utils::{
    ParameterHashMap,
    RequestError,
    RequestHandler,
    RequestInfo
    };

Then implement the RequestInfo trait for your API client struct. Trait to provide some basic info about API :

struct MyApiClient;

impl RequestInfo for MyApiClient {
    ...
}

Then implement the RequestModifiers trait for your API client struct. This trait provides methods for modifying the struct in a specific way:

impl RequestModifiers for MyApiClient {
    ...
}

Then implement the RequestHandler trait for your API client struct. This trait provides the request method for sending HTTP requests :

impl RequestHandler for MyApiClient {
    ...
}

Now just combine the methods , data and parameters / json to make the request and handle the error

Please note that the examples provided here are simplified and serve as a starting point. For comprehensive documentation of the crate, please visit the crate documentation for a better understanding of the crate’s functionalities and APIs.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request.

Re-exports

Enums

  • Enum representing different types of request errors.

Traits

  • The RequestDefaults trait provides a set of default methods for configuring and modifying HTTP requests.
  • A trait for handling HTTP requests.
  • Trait to provide some basic info about API
  • This trait provides methods for modifying the struct in a specific way:

Type Definitions

  • A HashMap type used for storing parameters with optional values. The keys are string references, and the values are optional string references.