ReqFly.Steps (req_fly v1.0.0)
View SourceCustom Req pipeline steps for Fly.io API integration.
This module provides request and response processing steps that integrate with the Req HTTP client pipeline to handle Fly.io-specific requirements like authentication, error handling, and telemetry.
Pipeline Steps
attach_auth/1- Adds Authorization header with Bearer tokenattach_base_url/1- Sets the base URL for Fly.io APIattach_headers/1- Adds required headers (User-Agent, Accept)handle_error_response/1- Converts non-2xx responses to ReqFly.Errorattach_telemetry/1- Emits telemetry events for observability
Summary
Functions
Attaches the Authorization Bearer header to the request.
Attaches the base URL to the request from the :fly_base_url option.
Attaches standard headers required for Fly.io API requests.
Attaches telemetry to emit events during request lifecycle.
Handles error responses by converting non-2xx responses to ReqFly.Error.
Functions
@spec attach_auth(Req.Request.t()) :: Req.Request.t()
Attaches the Authorization Bearer header to the request.
Reads the token from the :fly_token option on the request.
Examples
iex> request = %Req.Request{options: %{fly_token: "secret"}}
iex> request = ReqFly.Steps.attach_auth(request)
iex> request.headers["authorization"]
["Bearer secret"]
@spec attach_base_url(Req.Request.t()) :: Req.Request.t()
Attaches the base URL to the request from the :fly_base_url option.
Examples
iex> request = %Req.Request{options: %{fly_base_url: "https://api.machines.dev/v1"}}
iex> request = ReqFly.Steps.attach_base_url(request)
iex> request.options.base_url
"https://api.machines.dev/v1"
@spec attach_headers(Req.Request.t()) :: Req.Request.t()
Attaches standard headers required for Fly.io API requests.
Adds:
- User-Agent: "req_fly/0.1.0 (+Req)"
- Accept: "application/json"
Examples
iex> request = %Req.Request{}
iex> request = ReqFly.Steps.attach_headers(request)
iex> request.headers["user-agent"]
["req_fly/0.1.0 (+Req)"]
@spec attach_telemetry(Req.Request.t()) :: Req.Request.t()
Attaches telemetry to emit events during request lifecycle.
Emits the following telemetry events:
[:req_fly, :request, :start]- When request starts[:req_fly, :request, :stop]- When request completes successfully[:req_fly, :request, :exception]- When request fails
The telemetry prefix can be customized using the :fly_telemetry_prefix option.
Examples
iex> request = %Req.Request{options: %{fly_telemetry_prefix: [:my_app, :fly]}}
iex> request = ReqFly.Steps.attach_telemetry(request)
@spec handle_error_response({:ok, Req.Response.t()} | {:error, Exception.t()}) :: {:ok, Req.Response.t()} | {:error, ReqFly.Error.t()}
Handles error responses by converting non-2xx responses to ReqFly.Error.
Examples
iex> response = %Req.Response{status: 404, body: %{"error" => "not_found"}}
iex> {:error, error} = ReqFly.Steps.handle_error_response({:ok, response})
iex> error.status
404