Krug.HttpUtil (Krug v2.0.27) 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
Functions
Makes a DELETE
request to a url.
Makes a GET
request to a url.
Makes a PATCH
request to a url.
Makes a POST
request to a url.
Makes a PUT
request to a url.
Link to this section Functions
make_delete_request(url, headers \\ [], options \\ [], debug \\ false, full_response \\ false)
View SourceMakes 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}
make_get_request(url, headers \\ [], options \\ [], debug \\ false, full_response \\ false)
View SourceMakes 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}
make_patch_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)
View SourceMakes 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}
make_post_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)
View SourceMakes 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}
make_put_request(url, json_body, headers \\ [], options \\ [], debug \\ false, full_response \\ false)
View SourceMakes 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}