# `HuggingfaceClient.Inference.HTTPClient`
[🔗](https://github.com/huggingface/huggingface_client/blob/v0.1.0/lib/huggingface_client/inference/http_client.ex#L1)

Behaviour for the underlying HTTP client, enabling Mox-based testing.

In production the default adapter (`HuggingfaceClient.Inference.HTTPClient.ReqAdapter`)
delegates to `Req`. In tests, set:

    # config/test.exs
    config :huggingface_client, :http_client, MyApp.MockHTTPClient

Then in your test module:

    Mox.defmock(MyApp.MockHTTPClient, for: HuggingfaceClient.Inference.HTTPClient)

## Example mock

    import Mox

    test "chat completion returns expected response", %{} do
      expect(MyApp.MockHTTPClient, :post, fn _url, _opts ->
        {:ok, %{status: 200, body: %{
          "id" => "test",
          "created" => 0,
          "model" => "test-model",
          "choices" => [%{"message" => %{"role" => "assistant", "content" => "Hi"}}],
          "usage" => %{}
        }, headers: []}}
      end)

      client = HuggingfaceClient.client("hf_test")
      assert {:ok, resp} = HuggingfaceClient.chat_completion(client, %{
        model: "test/model",
        messages: [%{role: "user", content: "hello"}]
      })
      assert resp["choices"] |> hd() |> get_in(["message", "content"]) == "Hi"
    end

# `response`

```elixir
@type response() :: %{status: non_neg_integer(), body: term(), headers: list()}
```

Simplified response type returned by the HTTP client

# `get`

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

Perform an HTTP GET request.

# `post`

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

Perform an HTTP POST request.

---

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