pub struct ApiClient { /* private fields */ }Expand description
Generic async JSON REST client. Generic async JSON REST client.
This client is transport-focused and does not require an OpenAPI operation id.
For operation-id based calls generated from openapi/openapi.json, use
crate::IriClient.
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(base_url: impl AsRef<str>) -> Result<Self, ClientError>
pub fn new(base_url: impl AsRef<str>) -> Result<Self, ClientError>
Creates a new client with the given base URL.
The URL is normalized to include a trailing slash, so relative endpoint paths join correctly.
Returns a new client with a raw access token attached to all requests.
This sets Authorization: <token> (without Bearer prefix).
Sourcepub async fn get_json(&self, path: &str) -> Result<Value, ClientError>
pub async fn get_json(&self, path: &str) -> Result<Value, ClientError>
Sends a GET request and parses the response as JSON.
Sourcepub async fn get_json_with_query(
&self,
path: &str,
query: &[(&str, &str)],
) -> Result<Value, ClientError>
pub async fn get_json_with_query( &self, path: &str, query: &[(&str, &str)], ) -> Result<Value, ClientError>
Sends a GET request with query parameters and parses the response as JSON.
Sourcepub async fn post_json(
&self,
path: &str,
body: Value,
) -> Result<Value, ClientError>
pub async fn post_json( &self, path: &str, body: Value, ) -> Result<Value, ClientError>
Sends a POST request with a JSON body and parses the response as JSON.
Sourcepub async fn put_json(
&self,
path: &str,
body: Value,
) -> Result<Value, ClientError>
pub async fn put_json( &self, path: &str, body: Value, ) -> Result<Value, ClientError>
Sends a PUT request with a JSON body and parses the response as JSON.
Sourcepub async fn delete_json(&self, path: &str) -> Result<Value, ClientError>
pub async fn delete_json(&self, path: &str) -> Result<Value, ClientError>
Sends a DELETE request and parses the response as JSON.
Sourcepub async fn request_json(
&self,
method: Method,
path: &str,
body: Option<Value>,
) -> Result<Value, ClientError>
pub async fn request_json( &self, method: Method, path: &str, body: Option<Value>, ) -> Result<Value, ClientError>
Sends a request and parses the response as JSON.
Use Self::request_json_with_query when query parameters are needed.
Sourcepub async fn request_json_with_query(
&self,
method: Method,
path: &str,
query: &[(&str, &str)],
body: Option<Value>,
) -> Result<Value, ClientError>
pub async fn request_json_with_query( &self, method: Method, path: &str, query: &[(&str, &str)], body: Option<Value>, ) -> Result<Value, ClientError>
Sends a request with query parameters and parses the response as JSON.
Returns Value::Null for successful responses with an empty body.