PropertyDamage.Export.HTTPSpec (PropertyDamage v0.2.0)
View SourceDescribes an HTTP call for export purposes.
This struct is used to map PropertyDamage commands to their HTTP representations, enabling the export of failure reports to standalone scripts (curl, Python, Elixir) that can reproduce the failure without the PropertyDamage framework.
Usage
Adapters can optionally implement http_spec/2 to provide HTTP specifications:
def http_spec(%CreateAccount{currency: currency}, _context) do
%HTTPSpec{
method: :post,
path: "/api/accounts",
body: %{currency: currency}
}
end
def http_spec(%CreditAccount{account_ref: id, amount: amount}, _context) do
%HTTPSpec{
method: :post,
path: "/api/accounts/:account_id/credit",
path_params: %{account_id: id},
body: %{amount: amount}
}
endPath Parameters
Use :param_name syntax in paths, with corresponding keys in path_params:
%HTTPSpec{
path: "/api/accounts/:account_id/transactions/:tx_id",
path_params: %{account_id: "acc_123", tx_id: "tx_456"}
}This renders as: /api/accounts/acc_123/transactions/tx_456
Summary
Functions
Builds the full URL with resolved path and query parameters.
Checks if the spec has a request body.
Returns the HTTP method as an uppercase string.
Creates a new HTTPSpec struct.
Resolves path parameters in the path string.
Types
Functions
Builds the full URL with resolved path and query parameters.
Examples
iex> spec = %HTTPSpec{path: "/accounts", query_params: %{page: 1, limit: 10}}
iex> HTTPSpec.build_url(spec, "http://localhost:4000")
"http://localhost:4000/accounts?limit=10&page=1"
Checks if the spec has a request body.
Returns the HTTP method as an uppercase string.
Creates a new HTTPSpec struct.
Options
:method- HTTP method (required):path- URL path with optional:paramplaceholders (required):body- Request body as a map (optional):headers- Additional headers as keyword list or list of tuples (optional):path_params- Map of path parameter values (optional):query_params- Map of query string parameters (optional)
Resolves path parameters in the path string.
Examples
iex> spec = %HTTPSpec{path: "/accounts/:id", path_params: %{id: "123"}}
iex> HTTPSpec.resolve_path(spec)
"/accounts/123"
iex> spec = %HTTPSpec{path: "/accounts/:id/tx/:tx_id", path_params: %{id: "a", tx_id: "b"}}
iex> HTTPSpec.resolve_path(spec)
"/accounts/a/tx/b"