reqt is an HTTP request manager, providing high level features to connect to a web API and handle requests.
reqt goal is to make communication with web APIs easy.
reqt provides high level interfaces to make connect, auth, pagination, filtering, ranging, sorting, and working with rate limits a breeze.
Web devs who need to interact with an API.
- connection
- authorization
- requests (REST)
- rate-limit (manual + automatic)
- pagination
- filters
- range
- sorting
Api<P: Pagination = RequestPagination, F: Filter = FilterRule, S: Sort = SortRule, R: Range = RangeRule>
Api Connector can be defined using the default Pagination, Filter, Sort and Range rules, or by implementing your own types that implement the following traits:
- Pagination
- Filter
- Sort
- Range
Each rule can be overridden for a specific request if needed later.
Authorization Type define how to use your token in each request:
- None => No token
- Basic
username and password are Base64 encoded
Authorization: Basic username:password - Bearer
Authorization: Bearer <token> - ApiKey
X-API-Key: 1234567890abcdef - OAuth2
Authorization: Bearer <access_token>
Authorization: Bearer <refresh_token> - OIDC
- Keycloak
Request<B: Serialize + Clone = (), P: Pagination = RequestPagination, F: Filter = FilterRule, S: Sort = SortRule, R: Range = RangeRule>
The request allow you to override pagination, filter, sort and range rules from the connector.
Pagination defines the rule to manage multiple page requests depending on the API specifications.
By default RequestPagination will be used and fields are set as follow:
size = 100=> Page sizecurrent_page = 1pagination = PaginationRule::OneShot
And the headers page[number]=x and page[size]=y are added to the final query of the request.
To implement your own pagination, you need to implement the Pagination trait.
- Fixed(X)
WhereXis the number of page you want collected by one request - OneShot
Filter defines the way to filter resources with your request, and the list of filters you want to apply.
To implement your own filter rule, you need to implement the Filter trait.
Range defines the way to range resources with your request, and the list of ranges you want to apply.
To implement your own range rule, you need to implement the Range trait.
Sort defines the way to sort resources with your request, and the list of sorts you want to apply.
To implement your own sort rule, you need to implement the Sort trait.
- Asc
- Desc
The rate limit can be set through the ApiBuilder (Default = RateLimiter::new(1, TimePeriod::Second)), and will allow the connector to respect a specific rate to avoid 429 HTTP errors.
To implement your own connector with ease, you have in your hands the following macros:
#[derive(Debug, Clone, Deserialize, Oauth2)]
#[pagination(PaginationTest)]
#[filter(FilterTest)]
#[sort(SortTest)]
#[range(RangeTest)]
struct TestApiConnector {
client_id: String,
client_secret: String,
auth_endpoint: String,
scopes: Vec<String>,
}Please always perform the following checks before committing:
- ⚙️
cargo build --workspace --all --all-features --tests - 🧼
cargo fmt --all - 🩺
cargo clippy --workspace --all --all-features --tests -- -D warnings - 🧪
cargo test --all-targets --all-features --workspace
This project is licensed under the MIT License. See LICENSE for details.
Huge thanks to gpoblon for his CI, ideas and reviews!