ExAzureCore.Http.Client (ex_azure_core v0.3.0)

Copy Markdown

HTTP client for Azure services using Req.

Provides a pre-configured Req client with Azure-specific plugins for authentication, error handling, and retry logic.

Creating a Client

client = ExAzureCore.Http.Client.new(base_url: "https://management.azure.com")

Making Requests

{:ok, response} = ExAzureCore.Http.Client.get(client, "/subscriptions")
{:ok, response} = ExAzureCore.Http.Client.post(client, "/resources", %{name: "example"})

With Plugins

client = ExAzureCore.Http.Client.new(
  base_url: "https://vault.azure.net",
  plugins: [
    {ExAzureCore.Http.Plugins.BearerToken, credential: :my_credential},
    {ExAzureCore.Http.Plugins.AzureHeaders, api_version: "7.4"}
  ]
)

Summary

Functions

Executes a DELETE request.

Executes a GET request.

Executes a HEAD request.

Creates a new HTTP client with the given options.

Executes an HTTP request using the given client.

Executes a streaming request.

Types

client()

@type client() :: Req.Request.t()

Functions

delete(client, url, opts \\ [])

@spec delete(client(), String.t(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a DELETE request.

get(client, url, opts \\ [])

@spec get(client(), String.t(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a GET request.

head(client, url, opts \\ [])

@spec head(client(), String.t(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a HEAD request.

new(opts \\ [])

@spec new(keyword()) :: client()

Creates a new HTTP client with the given options.

Options

  • :base_url - Base URL for all requests
  • :timeout - Request timeout in milliseconds (default: 30000)
  • :pool_timeout - Connection pool timeout (default: 5000)
  • :plugins - List of plugins to attach, as {Module, opts} or Module
  • :headers - Default headers for all requests

patch(client, url, body \\ nil, opts \\ [])

@spec patch(client(), String.t(), term(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a PATCH request.

post(client, url, body \\ nil, opts \\ [])

@spec post(client(), String.t(), term(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a POST request.

put(client, url, body \\ nil, opts \\ [])

@spec put(client(), String.t(), term(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a PUT request.

request(client, request)

@spec request(client(), ExAzureCore.Http.Request.t()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes an HTTP request using the given client.

Parameters

Returns

  • {:ok, response} - Successful response
  • {:error, error} - Network or HTTP error

stream(client, request_or_opts, opts \\ [])

@spec stream(client(), ExAzureCore.Http.Request.t() | keyword(), keyword()) ::
  {:ok, ExAzureCore.Http.Response.t()} | {:error, term()}

Executes a streaming request.

The into option determines how the response body is streamed:

  • into: File.stream!(path) - Stream to a file
  • into: fun - Stream to a function
  • into: :self - Stream to the calling process