http.class.sh

List of all functions in alphabetic order

http()

line: 97

http.addCurlparam()


Add an additional curl parameter

🟩 param  string  line to add, eg "Connection: keep-alive"

line: 701

http.addHeader()


Add a line to the request header

🟩 param  string  line to add, eg "Connection: keep-alive"

line: 690

http.dump()


Dump information about request and response

no params

line: 585

http.flushCache()


Flush the cache

no params

line: 884

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

line: 432

http.getRequestTs()


Get timestamp of the response as a Unix timestamp.

no param

returns string  the timestamp of the response

line: 418

http.getResponse()


Get response body

no param

returns string  the response body

line: 451

http.getResponseData()


Get curl data of this request with status, transferred bytes, speed, ...

no param

returns string  the response data

line: 464

http.getResponseHeader()


Get response header

no param

returns string  the response header

line: 477

http.getResponseRaw()


Get raw response (not available after import)

no params

no param

line: 490

http.getStatus()


Get Http status as string OK|Redirect|Error

no params

line: 501

http.getStatuscode()


Get Http status code of the request as 3 digit number

no params

line: 514

http.help()


show a help text

no params

line: 895

http.init()


Initialize the client

Initialize the client for a new request. Call this before any other
function. It will reset all variables.

line: 118

http.isClientError()


Was the repsonse a client error (4xx)

no params

line: 563

http.isError()


Was the repsonse a client error (4xx or 5xx)

no params

line: 552

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

line: 530

http.isRedirect()


Was the repsonse a redirect?

no params

line: 541

http.isServerError()


Was the repsonse a client error (5xx)

no params

line: 574

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

line: 293

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

line: 173

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

line: 260

http.responseDelete()


Delete an exported file; this is especially useful if you use
AUTOFILE functionality

🟩 param  string  filename with stored response

line: 661

http.responseExport()


Export response to a file

🔹 param  string  optional: custom filename

line: 619

http.responseImport()


Import a former response from a file

🟩 param  string  filename with stored response

line: 637

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

line: 712

http.setAuth()


Set basic authentication
Without given parameter, authentication is removed

🔹 param  string  optional: USER:PASSWORD

line: 728

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

line: 745

http.setBaseUrl()


Set a base url of an API
Remark: Then use http.setUrl to complet the url to request

🟩 param  string  url

line: 772

http.setBody()


Set body to send for PUTs and POSTs

🟩 param  string  body

line: 760

http.setCA()


set and unset CA cert file to use

🔹 param  string  optional: filename to use; no value to disable cafile

line: 784

http.setCacheFile()


Set cache file

🟩 param  string  filename

line: 873

http.setCacheTtl()


Set cache ttl in seconds

🟩 param  integer  ttl in seconds

line: 862

http.setDebug()


Enable or disable debug mode

🟩 param  integer  0|1

line: 795

http.setDocs()

line: 801

http.setFullUrl()


Set a full url to request

🔹 param  string  optional: url

line: 833

http.setInsecure()


Allow and disallow insecure connections

🔹 param  string  optional: 1 to enable insecure flag; no value to disable insecure flag

line: 811

http.setMethod()


Set the method to use; GET|POST|PUT|DELETE|...

🟩 param  string  name of method

line: 822

http.setUrl()


Complete the base url

🟩 param  string  url part behind base url

line: 848


Generated with Bashdoc v0.6