Table of Contents
-
http.class.sh
- http()
- http.addCurlparam()
- http.addHeader()
- http.dump()
- http.flushCache()
- http.getRequestAge()
- http.getRequestTs()
- http.getResponse()
- http.getResponseData()
- http.getResponseHeader()
- http.getResponseRaw()
- http.getStatus()
- http.getStatuscode()
- http.help()
- http.init()
- http.isClientError()
- http.isError()
- http.isOk()
- http.isRedirect()
- http.isServerError()
- http.loadcfg()
- http.makeRequest()
- http.quit()
- http.responseDelete()
- http.responseExport()
- http.responseImport()
- http.setAccept()
- http.setAuth()
- http.setAuthorization()
- http.setBaseUrl()
- http.setBody()
- http.setCA()
- http.setCacheFile()
- http.setCacheTtl()
- http.setDebug()
- http.setDocs()
- http.setFullUrl()
- http.setInsecure()
- http.setMethod()
- http.setUrl()
http.class.sh
List of all functions in alphabetic order
http()
http.addCurlparam()
Add an additional curl parameter
🟩 param string line to add, eg "Connection: keep-alive"
http.addHeader()
Add a line to the request header
🟩 param string line to add, eg "Connection: keep-alive"
http.dump()
Dump information about request and response
no params
http.flushCache()
Flush the cache
no params
http.getRequestAge()
Get age of the response in sec.
It is especially useful after responseImport
no param
returns integer age of the response in sec
http.getRequestTs()
Get timestamp of the response as a Unix timestamp.
no param
returns string the timestamp of the response
http.getResponse()
Get response body
no param
returns string the response body
http.getResponseData()
Get curl data of this request with status, transferred bytes, speed, ...
no param
returns string the response data
http.getResponseHeader()
Get response header
no param
returns string the response header
http.getResponseRaw()
Get raw response (not available after import)
no params
no param
http.getStatus()
Get Http status as string OK|Redirect|Error
no params
http.getStatuscode()
Get Http status code of the request as 3 digit number
no params
http.help()
show a help text
no params
http.init()
Initialize the client
Initialize the client for a new request. Call this before any other
function. It will reset all variables.
http.isClientError()
Was the repsonse a client error (4xx)
no params
http.isError()
Was the repsonse a client error (4xx or 5xx)
no params
http.isOk()
Check: was response a 2xx status code?
output is a statuscode if it matches ... or empty
Additionally you can verify the return code
$? -eq 0 means YES
$? -ne 0 means NO
no params
http.isRedirect()
Was the repsonse a redirect?
no params
http.isServerError()
Was the repsonse a client error (5xx)
no params
http.loadcfg()
Load a config file
This function is marked as deprecated.
It will be removed in the future.
🟩 param string config file name
Sourcing that file will set the following vars
- RestApiUser
- RestApiPassword
- RestApiBaseUrl
- RestApiDocs
The function will then set the "internal" vars
- http_req__auth
- http_req__fullurl
- http_req__docs
http.makeRequest()
Execute the request
🔹 param string optional: method; GET|POST|PUT|DELETE|...
🔹 param string optional: full url
🔹 param string optional: request body
description:
This function does the following:
1. Check if to use a cache
2. If not cached, make the request
3. If cached, use the cached result
http.quit()
Show error message with last return code and quit with this exitcode
This function is used to quit the script with a meaningful error message
and the exit code of the last command.
The message is printed to STDERR and contains the return code.
If a documentation URL is known, it is printed as a hint.
The exit code is the one of the last command.
To prevent the script from exiting when this function is called from a
sourced file, the exit is commented out.
no params
http.responseDelete()
Delete an exported file; this is especially useful if you use
AUTOFILE functionality
🟩 param string filename with stored response
http.responseExport()
Export response to a file
🔹 param string optional: custom filename
http.responseImport()
Import a former response from a file
🟩 param string filename with stored response
http.setAccept()
set Accept request header and override default
🟩 param string accept header value, eg text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
http.setAuth()
Set basic authentication
Without given parameter, authentication is removed
🔹 param string optional: USER:PASSWORD
http.setAuthorization()
Set authentication via Athorization header
Without given parameter, authorization is removed
🔹 param string optional: type, eg. Basic|Bearer|Negotiate
🔹 param string optional: token or encoded user + password
http.setBaseUrl()
Set a base url of an API
Remark: Then use http.setUrl to complet the url to request
🟩 param string url
http.setBody()
Set body to send for PUTs and POSTs
🟩 param string body
http.setCA()
set and unset CA cert file to use
🔹 param string optional: filename to use; no value to disable cafile
http.setCacheFile()
Set cache file
🟩 param string filename
http.setCacheTtl()
Set cache ttl in seconds
🟩 param integer ttl in seconds
http.setDebug()
Enable or disable debug mode
🟩 param integer 0|1
http.setDocs()
http.setFullUrl()
Set a full url to request
🔹 param string optional: url
http.setInsecure()
Allow and disallow insecure connections
🔹 param string optional: 1 to enable insecure flag; no value to disable insecure flag
http.setMethod()
Set the method to use; GET|POST|PUT|DELETE|...
🟩 param string name of method
http.setUrl()
Complete the base url
🟩 param string url part behind base url
Generated with Bashdoc v0.6