api_req_derive-0.5.0 has been yanked.
Make API calls more easier!
In v0.3, the attribute in derive macros is changed to #[api_req(...)] instead of #[api(...)] and #[payload(...)].
Advantage
For example:
use Method;
You can not only define the path, method, payload-format, pre-deserialize-action, and deserialize method, but also can format the path, headervalue with fields in the payload struct.
feature
stream- support stream response:RespStreamcookies- store cookies, which can be retrieved fromCOOKIE_JAR
Example
use ;
use ;
,
req = form, // use `form` to set body format instead of the default `json`
before_deserialize = )]
,
default_headers_env = , // get from env
redirect = none // set redirect policy
)]
;
# async ;
// this will send a POST request to http://example.com/payments/{customer_id}
// with form `{"amount": 0}`
For POST request, the payload will be serialized as json body by default.
For GET request, the payload will be serialized as query parameters (urlencoded) by default.
You can set the payload format by req attribute in the #[api_req(...)] attribute, avaliable values are:
- json
- query
- form
- body (payload:
Into<Body>)
One should ensure the req matches its Method.