https://github.com/notbad4u/query_params
Custom derive to automatically implement serialization to http query params for arbitrary structs.
https://github.com/notbad4u/query_params
custom-derive derive http-client macros query-params rust
Last synced: about 1 month ago
JSON representation
Custom derive to automatically implement serialization to http query params for arbitrary structs.
- Host: GitHub
- URL: https://github.com/notbad4u/query_params
- Owner: NotBad4U
- License: mit
- Created: 2017-08-11T22:23:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-19T23:23:11.000Z (almost 8 years ago)
- Last Synced: 2025-04-14T05:53:24.879Z (about 1 month ago)
- Topics: custom-derive, derive, http-client, macros, query-params, rust
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://travis-ci.org/NotBad4U/query_params)
[]()# QueryParams Derive
[Rust][rust] custom derive to automatically implement serialization to http query params for arbitrary structs. A simple `#[derive(QueryParams)]` will generate a function `to_query_params` for your struct.
## How it Works
```rust
#[macro_use]
extern crate query_params;#[derive(QueryParams)]
struct PullRequestsParametersApi {
page: i32,
sort: bool,
direction: String,
state: Vec,
// .. other interesting fields ..
}fn main() {
let pr = PullRequestsParametersApi {
page: 2,
sort: true,
direction: "asc",
state: vec!["open".to_string(), "closed".to_string()],
}println!("{}", pr.to_query_params()); // => ?page=2&sort=true&direction=asc&state=open,closed
}
```## Get Started
It's as simple as two steps:
1. Add `query_params` to your `Cargo.toml`
* manually* or with [cargo-edit](https://github.com/killercup/cargo-edit):
`cargo add derive_builder`2. Annotate your struct with `#[derive(QueryParams)]`
## Disclaimer :exclamation:
* Tuple structs and unit structs are not supported as they have no field names.
## [Documentation][doc]
Detailed explaination of all features and tips for troubleshooting.
### Contribution
Feel free to make a pull request :smiley:
[doc]: https://docs.rs/query_params
[rust]: https://www.rust-lang.org/