LatticeStripe.Response (LatticeStripe v0.2.0)

Copy Markdown View Source

Wraps a successful Stripe API response with metadata.

%LatticeStripe.Response{} holds the decoded response body (in data), HTTP status code, response headers, and the extracted request_id from the Request-Id header.

Bracket Access

For singular object responses, bracket access delegates to data:

{:ok, resp} = LatticeStripe.Client.request(client, req)
resp["id"]       # same as resp.data["id"]
resp["object"]   # same as resp.data["object"]

When data is a %LatticeStripe.List{}, bracket access always returns nil. Use resp.data.has_more, resp.data.data, etc. directly for list responses.

Request ID

The request_id field is extracted from the Request-Id response header for convenience — it's the most common header value needed for debugging. Use get_header/2 for any other header values.

Summary

Types

t()

A successful Stripe API response with metadata.

Functions

Returns all values for the given header name (case-insensitive).

Types

t()

@type t() :: %LatticeStripe.Response{
  data: map() | LatticeStripe.List.t() | nil,
  headers: [{String.t(), String.t()}],
  request_id: String.t() | nil,
  status: non_neg_integer() | nil
}

A successful Stripe API response with metadata.

Returned by LatticeStripe.Client.request/2 on success. The data field holds the decoded response body — either a plain map (singular resource) or a %LatticeStripe.List{} (list/search endpoints).

  • data - Decoded response body: a plain map or %LatticeStripe.List{}
  • status - HTTP status integer (e.g., 200, 201)
  • headers - List of {name, value} string tuples from the response
  • request_id - Stripe Request-Id header value (useful for support requests)

Functions

get_header(response, name)

@spec get_header(t(), String.t()) :: [String.t()]

Returns all values for the given header name (case-insensitive).

Returns [] if the header is not found.

Examples

Response.get_header(resp, "Request-Id")
# => ["req_abc123"]

Response.get_header(resp, "x-custom")
# => []