HTTP client abstraction for making HTTP requests.
This module provides a behaviour and default implementation for HTTP operations, allowing easy mocking in tests while using a real HTTP client in production.
Configuration
The HTTP client implementation can be configured in config.exs:
config :codex_sdk, :http_client_impl, Codex.HTTPClient.ReqFor testing, use the mock implementation:
config :codex_sdk, :http_client_impl, Codex.HTTPClient.MockUsage
# GET request
{:ok, response} = Codex.HTTPClient.get("https://api.example.com/data", [{"Authorization", "Bearer token"}])
response.status # => 200
response.body # => "{...}"
# POST request
{:ok, response} = Codex.HTTPClient.post("https://api.example.com/data", body, [{"Content-Type", "application/json"}])
Summary
Types
Callbacks
Functions
Performs an HTTP GET request.
Parameters
url- The URL to requestheaders- List of header tuples (optional, defaults to[])
Returns
{:ok, %{status: integer(), body: binary()}}on success{:error, reason}on failure
Performs an HTTP POST request.
Parameters
url- The URL to requestbody- The request body as a string (usually JSON)headers- List of header tuples (optional, defaults to[])
Returns
{:ok, %{status: integer(), body: binary()}}on success{:error, reason}on failure