HTTP.Response (http_fetch v0.1.0)

Represents an HTTP response with status, headers, body, and URL information.

Summary

Functions

Parses the response body as JSON using Elixir's built-in JSON module (available in Elixir 1.18+).

Reads the response body as text.

Types

t()

@type t() :: %HTTP.Response{
  body: String.t(),
  headers: %{required(String.t()) => String.t()},
  status: integer(),
  url: String.t()
}

Functions

json(response)

@spec json(t()) :: {:ok, map() | list()} | {:error, term()}

Parses the response body as JSON using Elixir's built-in JSON module (available in Elixir 1.18+).

Returns:

  • {:ok, map | list} if the body is valid JSON.

  • {:error, reason} if the body cannot be parsed as JSON.

text(response)

@spec text(t()) :: String.t()

Reads the response body as text.