Make API calls more easier!
In v0.3, the attribute in derive macros is changed to #[api_req(...)] instead of #[api(...)] and #[payload(...)].
In v0.5, we have better error spanned in proc-macro. And use array for headers instead of tuple. Add default_headers_env_value_or_omit attribute meta.
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, panic if not presented
default_headers_env_or_default = , // omit if not presented
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.