Sofa.Response (sofa v0.5.1)

Copy Markdown View Source

HTTP Response Handler for Sofa, the Elixir-native Apache CouchDB client

If the only tool you have is CouchDB, then everything looks like {:ok, :relax}

Examples

iex> Sofa.init() |> Sofa.client() |> Sofa.connect!() |> Sofa.raw("/_up")
%Sofa.Response{
  body: nil,
  headers: %{
    cache_control: "must-revalidate",
    content_length: 95,
    content_type: "application/json",
    couch_body_time: 0,
    couch_request_id: "aa6cc50741",
    date: "Sun, 25 Apr 2021 20:04:34 GMT",
    server: "CouchDB/3.1.1 (Erlang OTP/22)"
  },
  method: :get,
  query: [],
  status: 200,
  url: "http://localhost:5984/_up"
}

Summary

Types

The usual atoms for the statuses CouchDB documents, or the response itself

t()

Functions

The reason to return for a failed response: an atom for the statuses the CouchDB API documents on most endpoints, otherwise the response itself so nothing is lost.

Types

error()

@type error() ::
  :bad_request
  | :unauthorized
  | :forbidden
  | :not_found
  | :conflict
  | :precondition_failed
  | t()

The usual atoms for the statuses CouchDB documents, or the response itself

t()

@type t() :: %Sofa.Response{
  body: map() | binary() | nil,
  headers: map(),
  method: atom(),
  query: list() | binary(),
  status: integer() | nil,
  url: binary()
}

Functions

error(response)

@spec error(t()) :: error()

The reason to return for a failed response: an atom for the statuses the CouchDB API documents on most endpoints, otherwise the response itself so nothing is lost.

iex> Sofa.Response.error(%Sofa.Response{status: 404, method: :get, body: nil})
:not_found
iex> %Sofa.Response{status: 500, method: :get, body: nil} |> Sofa.Response.error() |> Map.get(:status)
500