macro_rules! fetch {
($url:literal, &mut $client:ident, $res_body_ty:ident, $res_ty:ty) => { ... };
($url:expr, &mut $client:ident, $res_body_ty:ident, $res_ty:ty) => { ... };
($url:expr, &mut $client:ident) => { ... };
}Expand description
Make a GET request to the specified URL.
The fetch! macro is a more generic version of the get! macro.
Its first argument is a string literal or a variable. Arrows are
used to specify the body serialization type and the output type.
You can use the JsonBody, XmlBody, MsgPack type for JSON, XML
and MessagePack serialization.
To help understand the macro arguments, here is an example:
fetch!(url, &mut client, body, ty)
§Arguments
url- The URL to make the GET request to.client- The client variable to use for the request.res_body_ty- The body type of the response.res_ty- The type of the response.
Please note url can be a string literal or a variable.
§Example
ⓘ
let mut client = Deboa::new();
let response = fetch!("https://jsonplaceholder.typicode.com/posts", &mut client, JsonBody, Post);
assert_eq!(response.id, 1);