use api_builder::{Endpoint, Query as _, ReqwestClient, RestClient, api_endpoint, api_rest_client};
#[derive(Debug, thiserror::Error)]
pub enum APIError {}
#[derive(Default, ReqwestClient)]
pub struct Client {
client: reqwest::blocking::Client,
}
#[api_rest_client(error = APIError, base = "\"https://example.com/v1/\"")]
impl RestClient for Client {}
#[derive(serde::Deserialize)]
struct Response {
_success: bool,
}
#[derive(serde::Serialize)]
struct Payload {
id: String,
test: String,
}
#[api_endpoint(method = GET, path = "\"ab\"", self_as_body = "application/json")]
impl Endpoint for Payload {}
impl Payload {
pub fn final_query<C: api_builder::Client>(
&self,
client: &C,
) -> Result<Response, api_builder::error::APIError<C::Error>> {
api_builder::query::Query::<Response, C>::finalise(
self,
api_builder::query::Query::<Response, C>::send(
self,
client,
api_builder::query::Query::<Response, C>::request(self, client)?,
)?,
)
}
}
fn main() {
let client = Client::default();
let payload = Payload {
id: "test".to_string(),
test: "test".to_string(),
};
let _response = payload.final_query(&client).unwrap();
let _response: Response = payload.query(&client).unwrap();
}