thinwrap_location_transport behaviour (thinwrap_location v1.3.0)
View SourceThe bring-your-own HTTP seam.
The library never depends on a third-party HTTP client. It defines this one
callback and ships thinwrap_location_httpc (OTP httpc) as the default. To
use hackney, gun, Finch, … implement the behaviour and pass it in the
config:
Config = #{provider => google, api_key => Key,
transport => {my_hackney_transport, #{pool => maps}}}.request/2 sends one request and returns one response. Rules:
- A non-2xx answer is a response, never an error: return
{ok, #{status := 404, ...}}. The connector owns status-to-error mapping. - Return
{error, timeout}(or any term containing the atomtimeout) when the request timed out, so callers get thetimeoutcode rather thanprovider_unavailable. - Any other
{error, Reason}is reported asprovider_unavailable. The reason is rendered to a redacted string; it is never returned as a term, because a client's error may embed the request URL and its credentials. {error, {connector_error, Error}}surfaces a ready-madethinwrap_location:connector_error/0unchanged (the default transport uses it to refuse non-httpsURLs).- Never follow redirects: a 3xx must come back as a response, or the provider's credentials would be re-sent to wherever it points.
Summary
Types
-type method() :: get | post.