Sms77.HTTPClient.request

You're seeing just the function request, go back to Sms77.HTTPClient module for more information.

Specs

Issues an HTTP request using a Request struct.

This function returns {:ok, response}, {:ok, async_response}, or {:ok, maybe_redirect} if the request is successful, {:error, reason} otherwise.

Redirect handling

If the option :follow_redirect is given, HTTP redirects are automatically follow if the method is set to :get or :head and the response's status_code is 301, 302 or 307.

If the method is set to :post, then the only status_code that get's automatically followed is 303.

If any other method or status_code is returned, then this function returns a returns a {:ok, %HTTPoison.MaybeRedirect{}} containing the redirect_url for you to re-request with the method set to :get.

Examples

request = %HTTPoison.Request{
  method: :post,
  url: "https://my.website.com",
  body: "{\"foo\": 3}",
  headers: [{"Accept", "application/json"}]
}

request(request)
Link to this function

request(method, url, body \\ "", headers \\ [], options \\ [])

View Source

Specs

Issues an HTTP request with the given method to the given url.

This function is usually used indirectly by get/3, post/4, put/4, etc

Args:

  • method - HTTP method as an atom (:get, :head, :post, :put, :delete, etc.)
  • url - target url as a binary string or char list
  • body - request body. See more below
  • headers - HTTP headers as an orddict (e.g., [{"Accept", "application/json"}])
  • options - Keyword list of options

Body: see type HTTPoison.Request

Options: see type HTTPoison.Request

This function returns {:ok, response}, {:ok, async_response}, or {:ok, maybe_redirect} if the request is successful, {:error, reason} otherwise.

Redirect handling

If the option :follow_redirect is given, HTTP redirects are automatically follow if the method is set to :get or :head and the response's status_code is 301, 302 or 307.

If the method is set to :post, then the only status_code that get's automatically followed is 303.

If any other method or status_code is returned, then this function returns a returns a {:ok, %HTTPoison.MaybeRedirect{}} containing the redirect_url for you to re-request with the method set to :get.

Examples

request(:post, "https://my.website.com", "{\"foo\": 3}", [{"Accept", "application/json"}])