pub struct HttpClient { /* private fields */ }Expand description
HTTP client for OpenCode REST API.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(cfg: HttpConfig) -> Result<Self>
pub fn new(cfg: HttpConfig) -> Result<Self>
Create a new HTTP client with the given configuration.
§Errors
Returns an error if the HTTP client cannot be built.
Sourcepub fn from_parts(
base_url: Url,
directory: Option<PathBuf>,
http: Option<ReqClient>,
) -> Result<Self>
pub fn from_parts( base_url: Url, directory: Option<PathBuf>, http: Option<ReqClient>, ) -> Result<Self>
Create from base URL, directory, and optional existing client.
§Errors
Returns an error if the HTTP client cannot be built.
Sourcepub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>
GET request returning deserialized JSON.
§Errors
Returns an error if the request fails or response cannot be deserialized.
Sourcepub async fn delete<T: DeserializeOwned>(&self, path: &str) -> Result<T>
pub async fn delete<T: DeserializeOwned>(&self, path: &str) -> Result<T>
DELETE request returning deserialized JSON.
§Errors
Returns an error if the request fails or response cannot be deserialized.
Sourcepub async fn delete_empty(&self, path: &str) -> Result<()>
pub async fn delete_empty(&self, path: &str) -> Result<()>
Sourcepub async fn post<TReq: Serialize, TRes: DeserializeOwned>(
&self,
path: &str,
body: &TReq,
) -> Result<TRes>
pub async fn post<TReq: Serialize, TRes: DeserializeOwned>( &self, path: &str, body: &TReq, ) -> Result<TRes>
POST request with JSON body returning deserialized JSON.
§Errors
Returns an error if the request fails or response cannot be deserialized.
Sourcepub async fn patch<TReq: Serialize, TRes: DeserializeOwned>(
&self,
path: &str,
body: &TReq,
) -> Result<TRes>
pub async fn patch<TReq: Serialize, TRes: DeserializeOwned>( &self, path: &str, body: &TReq, ) -> Result<TRes>
PATCH request with JSON body returning deserialized JSON.
§Errors
Returns an error if the request fails or response cannot be deserialized.
Sourcepub async fn put<TReq: Serialize, TRes: DeserializeOwned>(
&self,
path: &str,
body: &TReq,
) -> Result<TRes>
pub async fn put<TReq: Serialize, TRes: DeserializeOwned>( &self, path: &str, body: &TReq, ) -> Result<TRes>
PUT request with JSON body returning deserialized JSON.
§Errors
Returns an error if the request fails or response cannot be deserialized.
Sourcepub async fn request_json<T: DeserializeOwned>(
&self,
method: Method,
path: &str,
body: Option<Value>,
) -> Result<T>
pub async fn request_json<T: DeserializeOwned>( &self, method: Method, path: &str, body: Option<Value>, ) -> Result<T>
Make a JSON request and deserialize the response.
§Errors
Returns an error if the request fails or the response cannot be deserialized.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more