# `Codex.HTTPClient`
[🔗](https://github.com/nshkrdotcom/codex_sdk/blob/v0.18.1/lib/codex/http_client.ex#L1)

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.Req

For testing, use the mock implementation:

    config :codex_sdk, :http_client_impl, Codex.HTTPClient.Mock

## Usage

    # 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"}])

# `headers`

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

# `response`

```elixir
@type response() :: %{status: integer(), body: binary() | map()}
```

# `get`

```elixir
@callback get(url :: String.t(), headers :: headers()) ::
  {:ok, response()} | {:error, term()}
```

# `post`

```elixir
@callback post(url :: String.t(), body :: String.t(), headers :: headers()) ::
  {:ok, response()} | {:error, term()}
```

# `get`

```elixir
@spec get(String.t(), headers()) :: {:ok, response()} | {:error, term()}
```

Performs an HTTP GET request.

## Parameters

  * `url` - The URL to request
  * `headers` - List of header tuples (optional, defaults to `[]`)

## Returns

  * `{:ok, %{status: integer(), body: binary()}}` on success
  * `{:error, reason}` on failure

# `post`

```elixir
@spec post(String.t(), String.t(), headers()) :: {:ok, response()} | {:error, term()}
```

Performs an HTTP POST request.

## Parameters

  * `url` - The URL to request
  * `body` - 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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
