MistralClient.Behaviours.HttpClient behaviour (mistralex_ai v0.1.0)

View Source

Behaviour for HTTP client implementations.

This behaviour defines the contract for HTTP clients used by the Mistral SDK. It allows for easy mocking in tests while maintaining a consistent interface.

Summary

Callbacks

Performs a streaming HTTP request for Server-Sent Events.

Types

body()

@type body() :: String.t() | map() | nil

headers()

@type headers() :: [{String.t(), String.t()}]

method()

@type method() :: :get | :post | :put | :patch | :delete

options()

@type options() :: keyword()

response()

@type response() :: {:ok, map()} | {:error, term()}

url()

@type url() :: String.t()

Callbacks

request(method, url, headers, body, options)

@callback request(method(), url(), headers(), body(), options()) :: response()

Performs an HTTP request.

Parameters

  • method - HTTP method (:get, :post, :put, :patch, :delete)
  • url - Request URL
  • headers - List of request headers as tuples
  • body - Request body (string, map, or nil)
  • options - Additional options (timeout, etc.)

Returns

  • {:ok, response} - Successful response with parsed body
  • {:error, reason} - Error response

stream_request(method, url, headers, body, options)

@callback stream_request(method(), url(), headers(), body(), options()) ::
  {:ok, Enumerable.t()} | {:error, term()}

Performs a streaming HTTP request for Server-Sent Events.

Parameters

  • method - HTTP method (typically :post for streaming)
  • url - Request URL
  • headers - List of request headers as tuples
  • body - Request body (string, map, or nil)
  • options - Additional options including stream handling

Returns

  • {:ok, stream} - Stream of events
  • {:error, reason} - Error response