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 and Accepts
  • 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 and ibrowse, 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 and request_headers for raw HTTPill calls. No overrides needed!

    • BONUS: also a standard way to set config options to your HTTPill.Base extensions

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

Link to this function after_process_request(request) View Source
after_process_request(HTTPill.Request.t) :: HTTPill.Request.t

Called after processing any request

Link to this function after_process_response(response) View Source
after_process_response(HTTPill.Response.t) :: HTTPill.Response.t

Called after processing any response

Link to this function before_process_request(request) View Source
before_process_request(HTTPill.Request.t) :: HTTPill.Request.t

Called before processing any request

Link to this function before_process_response(response) View Source
before_process_response(HTTPill.Response.t) :: HTTPill.Response.t

Called before processing any response

Returns the configuration for this module.

Link to this function delete(url, options \\ []) View Source

Issues a DELETE request to the given url.

See request/3 for more detailed information.

Issues a DELETE request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Issues a GET request to the given url.

See request/3 for more detailed information.

Issues a GET request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Issues a HEAD request to the given url.

See request/3 for more detailed information.

Issues a HEAD request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Link to this function options(url, options \\ []) View Source
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.

Issues a OPTIONS request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Issues a PATCH request to the given url.

See request/3 for more detailed information.

Issues a PATCH request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

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.

Issues a POST request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Link to this function process_any_async_response(response) View Source

Called after processing any async response

Issues a PUT request to the given url.

See request/3 for more detailed information.

Issues a PUT request to the given url, raising an exception in case of failure.

See request!/3 for more detailed information.

Link to this function request(method, url, options \\ []) View Source
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"}])
Link to this function request!(method, url, options \\ []) View Source
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.

Requests the next message to be streamed for a given HTTPill.AsyncResponse.

See request!/3 for more detailed information.