diff --git a/inc/rest-api-client.sh b/inc/rest-api-client.sh index ab6e9e48f01647e556889a9301b24caadf06a9be..0ac9e9d0a66aedb0a7ea3eb973d33e90988245ae 100644 --- a/inc/rest-api-client.sh +++ b/inc/rest-api-client.sh @@ -22,9 +22,10 @@ # 2022-01-11 v0.7 axel.hahn@iml.unibe.ch fixes using shellcheck # 2024-10-09 v0.8 axel.hahn@unibe.ch add setAuthorization; customize accept header, add custom request headers # 2024-10-10 v0.9 axel.hahn@unibe.ch update docs +# 2024-10-23 v0.10 axel.hahn@unibe.ch update help # ====================================================================== - http_cfg__about="Bash REST API client v0.9" + http_cfg__about="Bash REST API client v0.10" typeset -i http_cfg__debug=0 typeset -i http_cfg__cacheTtl=0 http_cfg__cacheDir=/var/tmp/http-cache @@ -867,7 +868,7 @@ INSTRUCTION: - Then you can run functions starting with "http." http.init - Start a new request. It resets internal vars of the last response + Start a new request. It resets internal vars of the last request (if there was one). http.setDebug 0|1 @@ -876,52 +877,54 @@ INSTRUCTION: - initialize a request - setAccept ACCEPT + setAccept "<ACCEPTHEADER>" Set authentication with user and password for basic auth Default: $http_req__accept - setAuth AUTH:PASSWORD + setAuth "<USER>:<PASSWORD>" Set authentication with user and password for basic auth Without given parameter, authentication is removed - setAuthorization TYPE TOKEN|HASH + setAuthorization "<TYPE>" "<TOKEN|HASH>" Set authentication with Authorization header. As TYPE you can use Basic|Bearer|Negotiate|... - 2nd param is the token or hased user+password + 2nd param is the token or hashed user+password Without given parameter, authorization is removed - http.setBody DATA + http.setBody "<DATA>" set a body for POST/ PUT requests. - http.setBaseUrl URL + http.setBaseUrl "<URL>" Set a base url to an api. renmark: Use http.setUrl to built a complete url. - http.setDocs URL + http.setDocs "<URL>" + Set a docs url. If set it will be shown as additional hint when a + request fails. - http.setMethod METHOD + http.setMethod "<METHOD>" Set a http method. Use an uppercase string for GET|POST|PUT|DELETE|... - http.setFullUrl URL + http.setFullUrl "<URL>" Set a complete url for a request. - http.setUrl REQUEST?QUERY + http.setUrl "<REQUEST?QUERY>" Set a relative url for a request. This requires to use http.setBaseUrl before. - http.addHeader HEADER_LINE + http.addHeader "<HEADER_LINE>" Add a header line to the request. This command can be repeated multiple times. - caching functions - http.setCacheTtl SECONDS + http.setCacheTtl <SECONDS> Enable caching with values > 0 Remark: only GET requests will be cached. Default: 0 (no caching) - http.setCacheFile FILENAME + http.setCacheFile "<FILENAME>" Set a file where to read/ store a request Default: empty; autogenerated file below $http_cfg__cacheDir @@ -930,10 +933,10 @@ INSTRUCTION: - make the request - http.makeRequest [[METHOD] [URL] [BODY]] - The parameters are optional. Without parameter the rquest will be + http.makeRequest [[<METHOD>] ["<URL>"] ["<BODY>"]] + The parameters are optional. Without parameter the request will be started with given data in http.set* functions described above. - If minimum one pram is given then they are handled: + If minimum one param is given then they are handled: METHOD optional: set a method (must be uppercase) - see http.setMethod URL set a relative url - see http.setUrl BODY optional: set a body - see http.setBody @@ -987,7 +990,7 @@ INSTRUCTION: - import/ export - http.responseExport [FILE] + http.responseExport ["<FILE>"] dump the response data Without parameter it is written on STDOUT. You can set a filename to write it to a file. @@ -998,7 +1001,7 @@ INSTRUCTION: http.makeRequest "https://example.com/api/" http.responseExport /tmp/something_AUTOFILE_.txt - http.responseImport FILE + http.responseImport "<FILE>" Import an export file. To use the AUTOFILE mechanism from export set the url first. @@ -1006,7 +1009,7 @@ INSTRUCTION: http.setFullUrl "https://example.com/api/" http.responseImport /tmp/something_AUTOFILE_.txt - http.responseDelete FILE + http.responseDelete "<FILE>" Delete a file after http.responseExport. It is useful if you use the AUTOFILE mechanism.