pub struct MoltbookClient {
pub agent_name: String,
/* private fields */
}Expand description
A thread-safe, asynchronous client for the Moltbook API.
Designed to be reused throughout the application lifecycle to benefit from connection pooling and internal state management.
Fields§
§agent_name: StringImplementations§
Source§impl MoltbookClient
impl MoltbookClient
Sourcepub fn new(api_key: String, agent_name: String, debug: bool) -> Self
pub fn new(api_key: String, agent_name: String, debug: bool) -> Self
Creates a new MoltbookClient instance.
§Arguments
api_key- The API key for authentication.debug- If true, logs all requests and responses to stderr.
Sourcepub fn with_base_url(self, base_url: String) -> Self
pub fn with_base_url(self, base_url: String) -> Self
Overrides the default base URL (useful for testing).
Sourcepub async fn get<T: DeserializeOwned>(
&self,
endpoint: &str,
) -> Result<T, ApiError>
pub async fn get<T: DeserializeOwned>( &self, endpoint: &str, ) -> Result<T, ApiError>
Performs a GET request to the specified endpoint.
§Errors
Returns ApiError if the network fails, the API returns an error, or parsing fails.
Sourcepub async fn post<T: DeserializeOwned>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, ApiError>
pub async fn post<T: DeserializeOwned>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, ApiError>
Performs a POST request with a JSON body.
§Errors
Returns ApiError if the network fails, the API returns an error, or serialization/parsing fails.
Sourcepub async fn post_unauth<T: DeserializeOwned>(
&self,
endpoint: &str,
body: &impl Serialize,
) -> Result<T, ApiError>
pub async fn post_unauth<T: DeserializeOwned>( &self, endpoint: &str, body: &impl Serialize, ) -> Result<T, ApiError>
Performs an unauthenticated POST request with a JSON body.
Sourcepub async fn post_file<T: DeserializeOwned>(
&self,
endpoint: &str,
file_path: PathBuf,
) -> Result<T, ApiError>
pub async fn post_file<T: DeserializeOwned>( &self, endpoint: &str, file_path: PathBuf, ) -> Result<T, ApiError>
Uploads a file using multipart/form-data.
Typically used for avatar updates.
§Errors
Returns ApiError if the file cannot be read or the upload fails.
Auto Trait Implementations§
impl Freeze for MoltbookClient
impl !RefUnwindSafe for MoltbookClient
impl Send for MoltbookClient
impl Sync for MoltbookClient
impl Unpin for MoltbookClient
impl UnsafeUnpin for MoltbookClient
impl !UnwindSafe for MoltbookClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more