View Source ExCurl (ex_curl v0.1.0)

Documentation for ExCurl.

shared-options

Shared options

  • :headers - a map of headers to include in the request, defaults to %{"user-agent" => "curl/7.85.0"}
  • :body - a string to send as the request body, defaults to ""
  • :follow_location - if redirects should be followed, defaults to true
  • :ssl_verifyhost - if SSL certificates should be verified, defaults to true
  • :ssl_verifypeer - if SSL certificates should be verified, defaults to true
  • :return_metrics - if request timing metrics should be included in the returned results, defaults to false
  • :verbose - if curl should output verbose logs to stdout, useful for debugging. Defaults to false

error-messages

Error messages

Error messages refer to error codes on the curl 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 curl error codes documentation.

Link to this section Summary

Functions

Sends a DELETE request to the given url. Similar to delete/2 but raises ExCurl.CurlError if the request fails.

Sends a DELETE 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 GET 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 PATCH 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 POST 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.

Sends a PUT request to the given url.

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.

Send a request to the url using the provided method and options

Link to this section Functions

Link to this function

delete!(url, opts \\ [])

View Source

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

Examples

iex> ExCurl.delete!("https://httpbin.org/delete")

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

Examples

iex> ExCurl.delete("https://httpbin.org/delete", headers: %{"authentication" => "bearer secret"})

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

Examples

iex> %ExCurl.Response{status_code: status_code} = ExCurl.get!("https://google.com")
iex> status_code
200

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

Examples

 iex> {:ok, %ExCurl.Response{status_code: status_code}} = ExCurl.get("https://google.com", follow_location: false)
 iex> status_code
 301

 iex> ExCurl.get("https://\n\n")
 {:error, "URL_MALFORMAT"}

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

Examples

iex> ExCurl.patch!("https://httpbin.org/patch", body: Jason.encode!(%{"some-value" => true}), headers: %{"content-type" => "application/json"})

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

Examples

iex> ExCurl.patch("https://httpbin.org/patch", headers: %{"user-agent" => "custom-user-agent"})

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

Examples

iex> ExCurl.post!("https://httpbin.org/post", body: "some-value=true")

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

Examples

 iex> {:ok, %ExCurl.Response{body: body}} = ExCurl.post("https://httpbin.org/post", body: "some-value=true")
 iex> Jason.decode!(body)["form"]
 %{"some-value" => "true"}

 iex> ExCurl.post("https://\n\n")
 {:error, "URL_MALFORMAT"}

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

Examples

iex> ExCurl.put!("https://httpbin.org/put", headers: %{"content-type" => "application/json"}, body: "{}")

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

Examples

 iex> ExCurl.put("https://httpbin.org/put", body: "some-value=true")
Link to this function

request!(method, url, opts \\ [])

View Source

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.

Link to this function

request(method, url, opts \\ [])

View Source

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

Examples

iex> ExCurl.request("GET", "https://google.com")

iex> ExCurl.request("POST", "https://google.com")