1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use anyhow::Result;
use yew::{format::Json, services::fetch::Response as FetchResponse};
pub type Response<T> = FetchResponse<Json<Result<T>>>;
#[macro_export]
macro_rules! fetch {
($request:expr => $api:expr, $link:expr, $msg:expr, $succ:expr, $err:expr) => {
match ::yew::services::fetch::Request::post(env!("API_URL").to_owned() + $api)
.header("Content-Type", "application/json")
.body(Json(&$request))
{
Ok(body) => {
$succ();
::yew::services::fetch::FetchService::fetch_binary(body, $link.callback($msg)).ok()
}
Err(_) => {
$err();
None
}
};
};
}