Geolixir.HttpClient (geolixir v0.1.3)
View SourceA simple HTTP client wrapper around HTTPoison, tailored for Geolixir providers.
This module handles making HTTP requests, processing responses (including basic JSON decoding), and normalizing success/error tuples. It is used internally by the various geocoding providers.
Summary
Types
Represents an error response map after processing.
Represents options passed to the underlying HTTP client (HTTPoison).
See HTTPoison.request/5
options for details.
Represents the configuration for an HTTP request.
Represents a successful response map after processing.
Functions
Makes an HTTP request using HTTPoison.
Types
@type error_response() :: %{ status_code: non_neg_integer(), body: any(), headers: [{String.t(), String.t()}] }
Represents an error response map after processing.
:status_code
: The HTTP status code (integer).:body
: The response body, decoded as JSON if possible, otherwise the raw string.:headers
: A list of response header tuples.
@type http_options() :: keyword()
Represents options passed to the underlying HTTP client (HTTPoison).
See HTTPoison.request/5
options for details.
@type request_config() :: %{ :method => :get | :post | :put | :delete | :patch, :url => String.t(), optional(:query_params) => map(), optional(:headers) => [{String.t(), String.t()}] }
Represents the configuration for an HTTP request.
:method
: The HTTP method (e.g.,:get
,:post
).:url
: The target URL string.:query_params
: (Optional) A map of query parameters. Defaults to%{}%
.:headers
: (Optional) A list of HTTP header tuples. Defaults to[]
.
@type success_response() :: %{ status_code: non_neg_integer(), body: any(), headers: [{String.t(), String.t()}] }
Represents a successful response map after processing.
:status_code
: The HTTP status code (integer).:body
: The response body, decoded as JSON if possible, otherwise the raw string.:headers
: A list of response header tuples.
Functions
@spec request(request_config(), config :: keyword()) :: {:ok, success_response()} | {:error, error_response() | HTTPoison.Error.t()}
Makes an HTTP request using HTTPoison.
It automatically decodes JSON responses and wraps the result in standardized
{:ok, response_map}
or {:error, error_map | HTTPoison.Error.t()}
tuples.
Parameters
request_config
: Arequest_config/0
map containing:method
,:url
, and optional:query_params
and:headers
.config
: (Optional) A keyword list for additional configuration.:http_options
: Ahttp_options/0
keyword list passed directly toHTTPoison.request/5
.
Returns
{:ok, success_response()}
: For successful HTTP requests (status 2xx).{:error, error_response()}
: For HTTP requests with error status codes (non-2xx).{:error, %HTTPoison.Error{}}
: If the HTTP request itself fails (e.g., connection error).