Skip to main content

HttpConnector

Trait HttpConnector 

Source
pub trait HttpConnector:
    Send
    + Sync
    + 'static {
    // Required methods
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        operation: &'life1 Operation,
        args: &'life2 Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn base_url(&self) -> &str;
}
Expand description

Backend-agnostic HTTP connector trait (OAPI-01).

The analog of crate::sql::SqlConnector for REST backends: an implementation executes an Operation against a configured base URL and returns the response body as JSON. base_url is the analog of SqlConnector::dialect() — a cheap accessor used by the synthesizer / prompt assembly.

§Example

A minimal connector. The example defines a LOCAL dummy struct so the doctest does not depend on any downstream crate (mirrors the SqlConnector doctest).

use pmcp_server_toolkit::http::{HttpConnector, HttpConnectorError, Operation};
use async_trait::async_trait;
use serde_json::Value;

struct Dummy;

#[async_trait]
impl HttpConnector for Dummy {
    fn base_url(&self) -> &str { "https://api.example.com/v1" }
    async fn execute(&self, _operation: &Operation, _args: &Value)
        -> Result<Value, HttpConnectorError> {
        Ok(Value::Null)
    }
}

Required Methods§

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, operation: &'life1 Operation, args: &'life2 Value, ) -> Pin<Box<dyn Future<Output = Result<Value, HttpConnectorError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute operation with the caller-supplied args (a JSON object whose keys map to path / query / header / body parameters) and return the response body as a serde_json::Value.

§Errors

Returns HttpConnectorError when the request fails at the transport layer (HttpConnectorError::Request), the backend returns a non-2xx status (HttpConnectorError::Status), authentication cannot be applied (HttpConnectorError::Auth), or a header is invalid (HttpConnectorError::InvalidHeader). Per the type-level Security note, no error message echoes a URL or credential.

Source

fn base_url(&self) -> &str

The configured base URL (analog of SqlConnector::dialect()).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§