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

Link to this section Functions

Link to this function

makeDeleteRequest(url, headers \\ [], options \\ [], debug \\ 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.

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}
Link to this function

makeGetRequest(url, headers \\ [], options \\ [], debug \\ 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.

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}
Link to this function

makePatchRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.

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}
Link to this function

makePostRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.

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}
Link to this function

makePutRequest(url, jsonbody, headers \\ [], options \\ [], debug \\ 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.

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}