use reqwest::Client;
use serde::{Deserialize, Serialize};
impl ApiClient for {{target}} {
{{#each endpoints}}
/// {{#if this.description}}{{this.description}}{{else}}{{this.name}}{{/if}}
pub async fn {{this.name}}(
&self,
{{#each this.params}}
{{this.name}}: {{this.ty}},
{{/each}}
{{#if this.body_param}}
form: {{this.body_param.ty}},
{{/if}}
) -> Result<{{this.response_type}}, reqwest::Error> {
let url = format!(
"{}{{this.path}}"{{#each this.params}}{{#if (eq this.location "path")}}, {{this.name}} = {{this.name}}{{/if}}{{/each}},
self.base_url
);
let client = Client::new();
let mut req = client.{{this.method}}(&url);
{{#if this.query_params.length}}
let query_params = vec![
{{#each this.query_params}}
("{{this.name}}", {{this.name}}.to_string()),
{{/each}}
];
req = req.query(&query_params);
{{/if}}
{{#if this.body_param}}
req = req.json(&form);
{{/if}}
let resp = req.send().await?;
{{#if (eq this.response_type "String")}}
Ok(resp.text().await?)
{{else}}
Ok(resp.json::<{{this.response_type}}>().await?)
{{/if}}
}
{{/each}}
}