Krug.HttpUtil (Krug v1.1.44) View Source

Utilitary module to handle HTTPoison requests and respectives fail/responses.

Useful to access external services with CORS restrictions in browser, or services that involves use of credentials that don't should be send/stored in browser/UI.

Link to this section Summary

Link to this section Functions

Link to this function

make_delete_request(url, headers \\ [], options \\ [], debug \\ false, full_response \\ false)

View Source

Makes a DELETE request to a url.

In case of success return a response.body.

If fail return nil.

If fail and was received a debug parameter as true, then return the fail reason.

The extra parameter 'full_response' returns the object 'response' if true or 'response.body' if false. make_delete_request(url,headers \ [], options \ [],debug \ false,full_response \ false)

Examples

iex > url = "www.google.com"
iex > Krug.HttpUtil.make_delete_request(url)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_delete_request(fake_url)
nil
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_delete_request(fake_url,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
Link to this function

make_get_request(url, headers \\ [], options \\ [], debug \\ false, full_response \\ false)

View Source

Makes a GET request to a url.

In case of success return a response.body.

If fail return nil.

If fail and was received a debug parameter as true, then return the fail reason.

The extra parameter 'full_response' returns the object 'response' if true or 'response.body' if false. make_get_request(url,headers \ [], options \ [],debug \ false,full_response \ false)

Examples

iex > url = "www.google.com"
iex > Krug.HttpUtil.make_get_request(url)
"<!doctype html><html ..."
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_get_request(fake_url)
nil
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_get_request(fake_url,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
Link to this function

make_patch_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)

View Source

Makes a PATCH request to a url.

In case of success return a response.body.

If fail return nil.

If fail and was received a debug parameter as true, then return the fail reason.

The extra parameter 'full_response' returns the object 'response' if true or 'response.body' if false. make_patch_request(url,headers \ [], options \ [],debug \ false,full_response \ false)

Examples

iex > url = "www.google.com"
iex > json_body = "{search: "ping"}"
iex > Krug.HttpUtil.make_patch_request(url,json_body)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_patch_request(fake_url,json_body)
nil
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_patch_request(fake_url,json_body,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
Link to this function

make_post_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)

View Source

Makes a POST request to a url.

In case of success return a response.body.

If fail return nil.

If fail and was received a debug parameter as true, then return the fail reason.

The extra parameter 'full_response' returns the object 'response' if true or 'response.body' if false. make_post_request(url,headers \ [], options \ [],debug \ false,full_response \ false)

Examples

iex > url = "www.google.com"
iex > json_body = "{search: "ping"}"
iex > Krug.HttpUtil.make_post_request(url,json_body)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_post_request(fake_url,json_body)
nil
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_post_request(fake_url,json_body,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
Link to this function

make_put_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)

View Source

Makes a PUT request to a url.

In case of success return a response.body.

If fail return nil.

If fail and was received a debug parameter as true, then return the fail reason.

The extra parameter 'full_response' returns the object 'response' if true or 'response.body' if false. make_put_request(url,headers \ [], options \ [],debug \ false,full_response \ false)

Examples

iex > url = "www.google.com"
iex > json_body = "{search: "ping"}"
iex > Krug.HttpUtil.make_put_request(url,json_body)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_put_request(fake_url,json_body)
nil
iex > fake_url = "www.fake_url.xxx"
iex > Krug.HttpUtil.make_put_request(fake_url,json_body,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}