Clientix
Clientix is a Rust library for building HTTP clients and requests declaratively with procedural macros - no need to write complex imperative or functional logic.
Description
With a simple procedural macro placed above a trait and its methods, Clientix lets you implement HTTP clients easily and efficiently - supporting both async and blocking modes. This makes it flexible enough to fit a wide range of scenarios, depending on your needs.
Currently, Clientix is built on top of reqwest with tokio as the async runtime. Future plans include adding support for other HTTP backends and giving you the ability to customize the underlying logic with minimal changes.
Usage
To get started, you only need to add a single dependency:
cargo add clientix
And if you prefer to declare it explicitly in your Cargo.toml, just add it under the [dependencies] section:
clientix = "0.0.4"
Examples
This section shows a few examples. For more details, please refer to the documentation.
Writing a synchronous blocking client:
use ;
use ;
However, writing a synchronous client comes with its trade-offs, so we also offer the option to implement an asynchronous client as a preferred alternative:
use ;
use ;
async
The examples above demonstrate very simple clients. If you want to, for instance, receive an object as a result or send one via POST, you'll need to define the corresponding DTOs using the #[data_transfer] procedural macro:
use HashMap;
use ;
use ;
async
Note the #[body] macro on the post method argument - it’s required to map an object to the request body. You also have the following argument macros available:
- #[segment] - maps method arguments to path segments
- #[query] - maps method arguments to query parameters
- #[header] - maps method arguments to request headers
Future plans include expanding the argument macros to provide more flexible client configuration options.
More examples can be found in the examples directory.
Support & Contribution
We’d be thrilled if you joined us in supporting and contributing to this project! Whether it’s reporting issues, suggesting improvements, or submitting pull requests, your help is always welcome. Together, we can make Clientix even better.