HTTPill v0.2.0 HTTPill View Source
HTTP requests for sick people!
The cure for some poison or potion you might be drinking in the web.
Why!?
Puns aside, HTTPoison and HTTPotion are both great tools, in the beginning this was nothing more than a merge of a lot of code from both, but we wanted more!
Here’s what we wanted:
- Debug logging
- Less callbacks to override, just one for requests and one for responses
- Auto JSON encoding/decoding for the request/response body according to
Content-Type
andAccepts
- Some slightly different response handling options, like returning
{:status_error, response}
for successful requests with status code >= 400, or not returning a tuple at all - Support for both
hackney
andibrowse
, or any other lib that comes to your mind in the future (and yes, you can switch between them anytime) Replaceable default configurations, like
base_url
andrequest_headers
for rawHTTPill
calls. No overrides needed!- BONUS: also a standard way to set config options to your
HTTPill.Base
extensions
- BONUS: also a standard way to set config options to your
Usage
The HTTPill
module can be used to make HTTP requests like this:
iex> HTTPill.get!("https://api.github.com")
%HTTPill.Response{status_code: 200,
headers: [{"content-type", "application/json"}],
body: "{...}"}
If you want to create your own HTTPill
extension, give HTTPill.Base
a
check. This module is nothing more than an empty module with only
use HTTPill.Base
, so you will find more documentation about how to make
requests there.
Link to this section Summary
Functions
Called after processing any request
Called after processing any response
Called before processing any request
Called before processing any response
Returns the configuration for this module
Issues a DELETE request to the given url
Issues a DELETE request to the given url, raising an exception in case of failure
Issues a GET request to the given url
Issues a GET request to the given url, raising an exception in case of failure
Issues a HEAD request to the given url
Issues a HEAD request to the given url, raising an exception in case of failure
Issues an OPTIONS request to the given url
Issues a OPTIONS request to the given url, raising an exception in case of failure
Issues a PATCH request to the given url
Issues a PATCH request to the given url, raising an exception in case of failure
Issues a POST request to the given url
Issues a POST request to the given url, raising an exception in case of failure
Called after processing any async response
Issues a PUT request to the given url
Issues a PUT request to the given url, raising an exception in case of failure
Issues an HTTP request with the given method to the given url
Issues an HTTP request with the given method to the given url, raising an exception in case of failure
Starts HTTPill and its dependencies
Requests the next message to be streamed for a given
HTTPill.AsyncResponse
Link to this section Functions
after_process_request(HTTPill.Request.t) :: HTTPill.Request.t
Called after processing any request
after_process_response(HTTPill.Response.t) :: HTTPill.Response.t
Called after processing any response
before_process_request(HTTPill.Request.t) :: HTTPill.Request.t
Called before processing any request
before_process_response(HTTPill.Response.t) :: HTTPill.Response.t
Called before processing any response
Returns the configuration for this module.
delete(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a DELETE request to the given url.
See request/3
for more detailed information.
delete!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a DELETE request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
get(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a GET request to the given url.
See request/3
for more detailed information.
get!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a GET request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
head(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a HEAD request to the given url.
See request/3
for more detailed information.
head!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a HEAD request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
options(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues an OPTIONS request to the given url.
See request/3
for more detailed information.
options!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a OPTIONS request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
patch(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a PATCH request to the given url.
See request/3
for more detailed information.
patch!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a PATCH request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
post(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a POST request to the given url.
Returns {:ok, response}
if the request is successful, {:error, reason}
otherwise.
See request/3
for more detailed information.
post!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a POST request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
process_any_async_response(HTTPill.AsyncResponse.any_t) :: HTTPill.AsyncResponse.any_t
Called after processing any async response
put(binary, Keyword.t) :: {:ok, HTTPill.Response.t | HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Issues a PUT request to the given url.
See request/3
for more detailed information.
put!(binary, Keyword.t) :: HTTPill.Response.t | HTTPill.AsyncResponse.t
Issues a PUT request to the given url, raising an exception in case of failure.
See request!/3
for more detailed information.
request(atom, binary, Keyword.t) :: HTTPill.Base.request_result
Issues an HTTP request with the given method to the given url.
This function is used indirectly by get/2
, post/2
, put/2
, etc
For information about the options, go check the HTTPill.Request
docs.
The return of this function depends on the response_handling_method
configured. Check HTTPill.Config
to check the available options and how
to set them.
Examples
request(:post, "https://my.website.com",
body: "{"foo": 3}",
headers: [{"Accept", "application/json"}])
request!(atom, binary, Keyword.t) :: HTTPill.Response.t
Issues an HTTP request with the given method to the given url, raising an exception in case of failure.
request!/3
works exactly like request/3
but it returns just the
response in case of a successful request, raising an exception in case the
request fails.
Starts HTTPill and its dependencies.
stream_next(HTTPill.AsyncResponse.t) :: {:ok, HTTPill.AsyncResponse.t} | {:error, HTTPill.ConnError.t}
Requests the next message to be streamed for a given
HTTPill.AsyncResponse
.
See request!/3
for more detailed information.