Hadorn
A type-safe HTTP client for Rust, inspire by retrofit.
Example
your Cargo.toml could look like this:
[]
= { = "0.1" }
= { = "0.12", = ["json"] }
And then the code:
use ;
use ;
use ;
use Deserialize;
async
Macro
-
hadorndefine a grouped apis
client、serialized、deserialized.-
client: generate theclientstruct name, default is the trait name appendClient -
serialized: the current trait all child apis default serialize type- Json =>
request.json(...) - Form =>
request.form(...) - Multipart =>
request.multipart(...) - no set =>
request.body(...)
- Json =>
-
deserialized: the current trait all child apis default deserialize type- Text =>
response.text() - Json =>
response.json() - Bytes =>
response.bytes() - Response =>
response - no set =>
()
- Text =>
-
-
get|post|put|delete|head|option|tracedefine a http request
method、path、headers、serialized、deserialzed.path: request path/api/user/<id>, use the<...>define a variable, example:/api/user/<id>contains a variableid.headers: request headers, examples:headers = [("content-type", "application/json")]serialized: same ofhadorn, priority is higher.deserialized: same ofhadorn, priority is higher.
-
#[path]|#[query]|#[header]|#[body]#[path]、#[query]、#[header]can set a literal to rename the argument name:#[path = "version"], if the request param name not equals arument name.#[body]mark the argument is request body argument, only appear once.
Notice
hadorn current only supported reqwest library, The support for other HTTP client libraries will be added
subsequently.
License
This project is licensed under the Apache 2.0