HTTPoison v1.5.0 HTTPoison.Base behaviour

Provides a default implementation for HTTPoison functions.

This module is meant to be use’d in custom modules in order to wrap the functionalities provided by HTTPoison. For example, this is very useful to build API clients around HTTPoison:

defmodule GitHub do
  use HTTPoison.Base

  @endpoint "https://api.github.com"

  def process_url(url) do
    @endpoint <> url
  end
end

The example above shows how the GitHub module can wrap HTTPoison functionalities to work with the GitHub API in particular; this way, for example, all requests done through the GitHub module will be done to the GitHub API:

GitHub.get("/users/octocat/orgs")
#=> will issue a GET request at https://api.github.com/users/octocat/orgs

Overriding functions

HTTPoison.Base defines the following list of functions, all of which can be overridden (by redefining them). The following list also shows the typespecs for these functions and a short description.

# Called in order to process the url passed to any request method before
# actually issuing the request.
@spec process_url(binary) :: binary
def process_url(url)

# Called to arbitrarily process the request body before sending it with the
# request.
@spec process_request_body(term) :: binary
def process_request_body(body)

# Called to arbitrarily process the request headers before sending them
# with the request.
@spec process_request_headers(term) :: [{binary, term}]
def process_request_headers(headers)

# Called to arbitrarily process the request options before sending them
# with the request.
@spec process_request_options(keyword) :: keyword
def process_request_options(options)

# Called before returning the response body returned by a request to the
# caller.
@spec process_response_body(binary) :: term
def process_response_body(body)

# Used when an async request is made; it's called on each chunk that gets
# streamed before returning it to the streaming destination.
@spec process_response_chunk(binary) :: term
def process_response_chunk(chunk)

# Called to process the response headers before returning them to the
# caller.
@spec process_headers([{binary, term}]) :: term
def process_headers(headers)

# Used to arbitrarily process the status code of a response before
# returning it to the caller.
@spec process_response_status_code(integer) :: term
def process_response_status_code(status_code)

Summary

Callbacks

Types

Callbacks

delete(url)
delete(url, headers)
delete(url, headers, options)
delete!(url, headers)
delete!(url, headers, options)
get(url, headers)
get(url, headers, options)
get!(url, headers, options)
head(url, headers)
head(url, headers, options)
head!(url, headers, options)
options(url)
options(url, headers)
options(url, headers, options)
options!(url, headers)
options!(url, headers, options)
patch(url, body)
patch(url, body, headers)
patch(url, body, headers, options)
patch!(url, body, headers)
patch!(url, body, headers, options)
post(url, body)
post(url, body, headers)
post(url, body, headers, options)
post!(url, body, headers)
post!(url, body, headers, options)
process_headers(list)
process_headers(list) :: term
process_request_body(body)
process_request_body(body) :: body
process_request_headers(headers)
process_request_headers(headers) :: headers
process_request_options(options)
process_request_options(options) :: options
process_request_params(params)
process_request_params(params) :: params
process_request_url(url)
process_request_url(url) :: url
process_response(response)
process_response(response) :: term
process_response_body(binary)
process_response_body(binary) :: term
process_response_chunk(binary)
process_response_chunk(binary) :: term
process_response_headers(list)
process_response_headers(list) :: term
process_response_status_code(integer)
process_response_status_code(integer) :: term
process_status_code(integer)
process_status_code(integer) :: term
process_url(url)
process_url(url) :: url
put(url, body)
put(url, body, headers)
put(url, body, headers, options)
put!(url, body, headers)
put!(url, body, headers, options)
request(atom, url)
request(atom, url) ::
  {:ok, HTTPoison.Response.t | HTTPoison.AsyncResponse.t} |
  {:error, HTTPoison.Error.t}
request(atom, url, body)
request(atom, url, body) ::
  {:ok, HTTPoison.Response.t | HTTPoison.AsyncResponse.t} |
  {:error, HTTPoison.Error.t}
request(atom, url, body, headers)
request(atom, url, body, headers, options)
request!(atom, url)
request!(atom, url, body)
request!(atom, url, body, headers)
request!(atom, url, body, headers, options)
start()
start :: {:ok, [atom]} | {:error, term}
stream_next(arg0)