api-request-utils
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:
= "0.2.4" # Note : Latest version at time of writing
Projects using api-request-utils-rs
Here are some projects that are using api-request-utils-rs
:
If you're using api-request-utils-rs
in your project, feel free to contact me to add it to this list!
Usage
Before you can start making API requests, you need to create an API client that implements the necessary traits. Here's an example of how you can define and implement the API client struct:
use *;
// Note : In most cases the default implementations are enough
// Implement methods for adding headers, modifying requests, etc.
// Implement default headers, parameters, and request builders
// Default settings should be enought
Making a GET Request
To make a GET request, you can use the get_request_handler
method provided by the RequestHandler
trait. Here's an example:
async
Making a POST Request
For making a POST request, you can utilize the post_request_handler
method similarly. Here's an example:
async
Error Handling
The library provides an RequestError
enum to handle different types of request errors. You can pattern match on this enum to handle specific error scenarios:
use RequestError;
match 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.