ExAzureCore.Http.Request (ex_azure_core v0.2.0)

Copy Markdown

Represents an HTTP request for Azure services.

Provides a normalized request structure that can be converted to Req options.

Creating a Request

request = ExAzureCore.Http.Request.new(
  method: :get,
  url: "/subscriptions",
  headers: %{"accept" => "application/json"}
)

Building Requests

request =
  Request.new(method: :post, url: "/resources")
  |> Request.put_header("content-type", "application/json")
  |> Request.put_query("api-version", "2024-01-01")
  |> Request.put_body(%{name: "example"})

Summary

Functions

Creates a new request with the given options.

Sets the request body.

Sets the body as form data and adds the content-type header.

Adds or updates a header in the request.

Merges multiple headers into the request.

Sets the body as JSON and adds the content-type header.

Adds or updates a query parameter.

Merges multiple query parameters into the request.

Converts the request to Req options.

Types

method()

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

t()

@type t() :: %ExAzureCore.Http.Request{
  body: term(),
  headers: %{required(String.t()) => String.t()},
  method: method(),
  options: keyword(),
  query: %{required(String.t()) => String.t()},
  url: String.t()
}

Functions

new(opts)

@spec new(keyword()) :: t()

Creates a new request with the given options.

Options

  • :method - Required. HTTP method atom
  • :url - Required. URL path or full URL
  • :headers - Optional. Map of headers
  • :body - Optional. Request body
  • :query - Optional. Query parameters map
  • :options - Optional. Additional Req options

put_body(request, body)

@spec put_body(t(), term()) :: t()

Sets the request body.

put_form(request, data)

@spec put_form(t(), keyword() | map()) :: t()

Sets the body as form data and adds the content-type header.

put_header(request, name, value)

@spec put_header(t(), String.t(), String.t()) :: t()

Adds or updates a header in the request.

Header names are normalized to lowercase.

put_headers(request, headers)

@spec put_headers(t(), %{required(String.t()) => String.t()} | keyword()) :: t()

Merges multiple headers into the request.

Header names are normalized to lowercase.

put_json(request, data)

@spec put_json(t(), term()) :: t()

Sets the body as JSON and adds the content-type header.

put_query(request, name, value)

@spec put_query(t(), String.t(), String.t()) :: t()

Adds or updates a query parameter.

put_query_params(request, params)

@spec put_query_params(t(), %{required(String.t()) => String.t()} | keyword()) :: t()

Merges multiple query parameters into the request.

to_req_options(request)

@spec to_req_options(t()) :: keyword()

Converts the request to Req options.