serverless-fn 0.1.0

A Rust library for simplifying serverless function development and invocation
Documentation
//! Transport layer abstraction for HTTP communication.

use std::collections::HashMap;
use std::time::Duration;

use async_trait::async_trait;

use crate::error::ServerlessError;

pub mod http;

/// Transport trait for sending and receiving data.
#[async_trait]
pub trait Transport: Send + Sync {
    /// Sends a request and receives a response.
    ///
    /// # Arguments
    ///
    /// * `function_name` - Name of the function to call
    /// * `payload` - Serialized function arguments
    /// * `headers` - Optional headers for the request
    ///
    /// # Errors
    ///
    /// Returns an error if the transport operation fails.
    async fn call(
        &self,
        function_name: &str,
        payload: Vec<u8>,
        headers: Option<HashMap<String, String>>,
    ) -> Result<Vec<u8>, ServerlessError>;
}

/// Returns the default HTTP transport.
#[must_use]
pub fn get_default_transport(timeout: Duration, retries: u32) -> Box<dyn Transport> {
    http::create_http_transport(timeout, retries)
}