ollama-sdk 0.2.3

An idiomatic, unofficial Rust client for the Ollama API with support for streaming, tool calling, and custom transports.
Documentation
use crate::Result;
use bytes::Bytes;
use serde::Serialize;

#[derive(Default, Debug)]
pub struct HttpRequest {
    pub url: String,
    pub verb: HttpVerb,
    pub body: Option<serde_json::Value>,
}

#[derive(Default, Debug)]
pub enum HttpVerb {
    #[default]
    GET,
    POST,
    PUT,
    DELETE,
}

#[derive(Debug)]
pub struct HttpResponse {
    pub body: Option<Bytes>,
}

impl HttpRequest {
    pub fn new(url: impl Into<String>) -> Self {
        Self {
            url: url.into(),
            ..Default::default()
        }
    }

    pub fn get(mut self) -> Self {
        self.verb = HttpVerb::GET;
        self
    }

    pub fn post(mut self) -> Self {
        self.verb = HttpVerb::POST;
        self
    }

    pub fn put(mut self) -> Self {
        self.verb = HttpVerb::PUT;
        self
    }

    pub fn delete(mut self) -> Self {
        self.verb = HttpVerb::DELETE;
        self
    }

    pub fn body<T: Serialize>(mut self, body: T) -> Result<Self> {
        self.body = Some(serde_json::to_value(body)?);
        Ok(self)
    }
}