ExCurl (ex_curl v0.4.0)
View SourceDocumentation for ExCurl.
Shared options
:headers- a map of headers to include in the request, defaults to%{"user-agent" => "ex_curl/0.4.0"}:body- a string to send as the request body, defaults to"":follow_location- if redirects should be followed, defaults totrue:ssl_verifyhost- if SSL certificates should be verified, defaults totrue:ssl_verifypeer- if SSL certificates should be verified, defaults totrue:return_metrics- if request timing metrics should be included in the returned results, defaults tofalse:verbose- if curl should output verbose logs to stdout, useful for debugging. Defaults tofalse:http_auth_negotiate- if curl should use HTTP Negotiation (SPNEGO) as defined in RFC 4559. Note: this flag requires curl to be compiled with a suitable GSS-API or SSPI library. Defaults tofalse:proxy- proxy to use for transfers. Can be hostname or IP address with optional port number. Supports various proxy types (http, https, socks4, socks5). Defaults tonil
Error messages
Error messages refer to error codes on the libcurl error codes documentation page.
For example, when we try to send a request to an invalid url:
iex> ExCurl.get("https://")
{:error, "URL_MALFORMAT"}The returned error tuple includes the error message "URL_MALFORMAT". This corresponds to the CURLE_URL_MALFORMAT (error code 3) error listed
in the libcurl error codes documentation.
Summary
Functions
Sends a DELETE request to the given url.
Sends a DELETE request to the given url. Similar to delete/2 but raises ExCurl.CurlError if the request fails.
Sends a GET request to the given url.
Sends a GET request to the given url. Similar to get/2 but raises ExCurl.CurlError if the request fails.
Sends a PATCH request to the given url.
Sends a PATCH request to the given url. Similar to patch/2 but raises ExCurl.CurlError if the request fails.
Sends a POST request to the given url.
Sends a POST request to the given url. Similar to post/2 but raises ExCurl.CurlError if the request fails.
Sends a PUT request to the given url.
Sends a PUT request to the given url. Similar to put/2 but raises ExCurl.CurlError if the request fails.
Send a request to the url using the provided method and options
Sends a request to the given url using the provided method and options. Similar to request/3 but raises ExCurl.CurlError if the request fails.
Functions
Sends a DELETE request to the given url.
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurl.delete("https://httpbin.org/delete", headers: %{"Authorization" => "bearer secret"})
Sends a DELETE request to the given url. Similar to delete/2 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurl.delete!("https://httpbin.org/delete")
Sends a GET request to the given url.
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> {:ok, %ExCurl.Response{status_code: status_code}} = ExCurl.get("https://google.com", follow_location: false)
iex> status_code
301
Sends a GET request to the given url. Similar to get/2 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> %ExCurl.Response{status_code: status_code} = ExCurl.get!("https://google.com")
iex> status_code
200
Sends a PATCH request to the given url.
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurl.patch("https://httpbin.org/patch", headers: %{"user-agent" => "custom-user-agent"})
Sends a PATCH request to the given url. Similar to patch/2 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurl.patch!("https://httpbin.org/patch", body: Jason.encode!(%{"some-value" => true}), headers: %{"content-type" => "application/json"})
Sends a POST request to the given url.
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> {:ok, %ExCurl.Response{}} = ExCurl.post("https://httpbin.org/post", body: "some-value=true")
Sends a POST request to the given url. Similar to post/2 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurl.post!("https://httpbin.org/post", body: "some-value=true")
Sends a PUT request to the given url.
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurl.put("https://httpbin.org/put", body: "some-value=true")
Sends a PUT request to the given url. Similar to put/2 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.
Examples
iex> ExCurl.put!("https://httpbin.org/put", headers: %{"content-type" => "application/json"}, body: "{}")
Send a request to the url using the provided method and options
Returns either {:ok, %ExCurl.Response{}} or {:error, "CURL_ERROR_MESSAGE"}.
See the "Shared options" section at the module documentation for available options and their defaults.
See the "Error messages" section for details on error messages.
Examples
iex> ExCurl.request("GET", "https://google.com")
Sends a request to the given url using the provided method and options. Similar to request/3 but raises ExCurl.CurlError if the request fails.
See the "Shared options" section at the module documentation for available options and their defaults.