Krug.HttpUtil (Krug v0.1.0) View Source
Utilitary module to handle HTTPoison requests and respectives fail/responses.
Useful to access external services whit 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
makeDeleteRequest(url, headers \\ [], options \\ [], debug \\ 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.
Examples
iex > url = "www.google.com"
iex > Krug.HttpUtil.makeDeleteRequest(url)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makeDeleteRequest(fakeUrl)
nil
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makeDeleteRequest(fakeUrl,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
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.
Examples
iex > url = "www.google.com"
iex > Krug.HttpUtil.makeGetRequest(url)
"<!doctype html><html ..."
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makeGetRequest(fakeUrl)
nil
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makeGetRequest(fakeUrl,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
makePatchRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.
Examples
iex > url = "www.google.com"
iex > jsonbody = "{search: "ping"}"
iex > Krug.HttpUtil.makePatchRequest(url,jsonbody)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePatchRequest(fakeUrl,jsonbody)
nil
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePatchRequest(fakeUrl,jsonbody,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
makePostRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.
Examples
iex > url = "www.google.com"
iex > jsonbody = "{search: "ping"}"
iex > Krug.HttpUtil.makePostRequest(url,jsonbody)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePostRequest(fakeUrl,jsonbody)
nil
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePostRequest(fakeUrl,jsonbody,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}
makePutRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.
Examples
iex > url = "www.google.com"
iex > jsonbody = "{search: "ping"}"
iex > Krug.HttpUtil.makePutRequest(url,jsonbody)
"<!doctype html><html ... Error 405 (Method Not Allowed) ..."
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePutRequest(fakeUrl,jsonbody)
nil
iex > fakeUrl = "www.fakeurl.xxx"
iex > Krug.HttpUtil.makePutRequest(fakeUrl,jsonbody,[],[],true)
%HTTPoison.Error{id: nil, reason: :nxdomain}