![]() |
Qore RestClient Module Reference 2.0.1
|
this class provides the REST client API More...
#include <RestClient.qm.dox.h>
Public Member Methods | |
| addDefaultHeaders (hash< auto > h) | |
| adds default headers to each request More... | |
| clearConnectionPath () | |
| Clears the connection path when a validator is present that manages the URI path. More... | |
| constructor (*hash< auto > opts, *softbool do_not_connect) | |
| calls the base class HTTPClient constructor and optionally connects to the REST server More... | |
| hash< auto > | del (string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr) |
sends an HTTP DELETE request to the REST server and returns the response More... | |
| hash< auto > | doRequest (string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr) |
| sends an HTTP request to the REST server and returns the response More... | |
| hash< auto > | doValidatedRequest (string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr) |
| The same as doRequest() except no schema validation is performed on the request. More... | |
| hash< auto > | get (string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr) |
sends an HTTP GET request to the REST server and returns the response More... | |
| hash< auto > | getDefaultHeaders () |
| returns the hash of default headers to sent in all requests More... | |
| *string | getSendEncoding () |
| returns the current data content encoding (compression) object or NOTHING if no encoding option is set More... | |
| string | getSerialization () |
| returns the current data serialization format currently in effect for the object More... | |
| *string | getToken () |
| Returns any token set for the connection. More... | |
| string | getTokenType () |
| Returns the token type for any token. More... | |
| RestSchemaValidator::AbstractRestSchemaValidator | getValidator () |
| returns the current validator object More... | |
| hash< auto > | gotOAuth2LoginInfo (hash< auto > h) |
| Called when OAuth2 login information has been received. More... | |
| hash< auto > | patch (string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr) |
sends an HTTP PATCH request to the REST server and returns the response More... | |
| hash< auto > | post (string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr) |
sends an HTTP POST request to the REST server and returns the response More... | |
| prepareToSend (string method, reference< string > path, reference< auto > body, *reference< hash< auto > > hdr) | |
| Prepares and processes message parameters for sending without sending the message. More... | |
| hash< auto > | processRestResponse (hash< auto > resp, string method, string path, *reference< hash< auto > > info) |
| Process the raw REST response received. More... | |
| hash< auto > | put (string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr) |
sends an HTTP PUT request to the REST server and returns the response More... | |
| replaceDefaultHeaders (*hash< auto > hdr) | |
| replaces default headers More... | |
| bool | requiresOAuth2Token () |
| Returns True if the client requires an OAuth2 token. More... | |
| setContentEncoding (string enc='auto') | |
| sets the request and desired response encoding for the object; see EncodingSupport for valid options More... | |
| setSendEncoding (string enc='auto') | |
| change the data content encoding (compression) option for the object More... | |
| setSerialization (string data='auto') | |
| change the serialization option for the object; see DataSerializationOptions for valid options More... | |
| setToken (string token_type, string token, *string refresh_token) | |
| Sets a token for authentication. More... | |
| setValidator (RestSchemaValidator::AbstractRestSchemaValidator validator) | |
| Sets a new REST schema validator. More... | |
| AbstractPollOperation | startOAuth2PollRefreshToken () |
| Starts an OAuth2 refresh token request in a non-blocking I/O operation. More... | |
| AbstractPollOperation | startOAuth2PollSendRecv () |
| Starts an OAuth2 token request in a non-blocking I/O operation. More... | |
| bool | usingOAuth2 () |
| Returns True if the client is configured for authentication with OAuth2. More... | |
Public Attributes | |
| const | Accept = AcceptList.join(",") |
| Accept header value. | |
| const | AcceptList = ... |
| Accept header list. | |
| const | AcceptMap = map {$1: True} |
| Map of acceptable Mime types. | |
| const | CompressionThreshold = 1024 |
| default threadhold for data compressions; transfers smaller than this size will not be compressed | |
| const | DataSerializationOptions |
| Data serialization options; this is a hash to simulate a set of strings. More... | |
| const | DataSerializationSupport |
| Data serialization support mapping codes to MIME types and de/serialization functions. | |
| const | DefaultHeaders |
| default HTTP headers (Content-Type is added before sending) | |
| const | DefaultOAuth2RedirectUrl = "auto" |
| Default oauth2_redirect_url option value. | |
| const | DefaultOptions |
| Default option values. | |
| const | EncodingSupport |
| Send content encoding options. More... | |
| const | MinimumTokenRefresh = 1m |
| Minimum time between OAuth2 token requests. | |
| const | OAuth2AuthHeaders |
| Headers to send when making an authorization / token request. | |
| const | OAuth2GrantOptions |
| Option requirements per OAuth2 grant type. More... | |
| const | Version = "2.0" |
| RestClient Version. | |
| const | VersionString = sprintf("Qore-RestClient/%s", RestClient::Version) |
| RestClient Version String. | |
Private Member Methods | |
| checkLogin (*reference< hash< auto > > info) | |
| Checks if a login is necessary; if so, then the login is performed. | |
| checkOAuth2Options (hash< auto > opts) | |
| Validates and sets any OAuth2 options. More... | |
| hash< auto > | doOAuth2LoginRequest (string url, hash< auto > login, *reference< hash< auto > > info) |
| Returns the deserialized response body of an OAuth2 authorization / token request. More... | |
| hash< auto > | doRequestIntern (string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr, *string assume_content_type) |
| Makes a REST request and returns the result. | |
| *hash< auto > | getOAuth2AuthHeaders () |
| Returns headers to use with OAuth2 authorization / token requests. More... | |
| hash< auto > | getOAuth2LoginInfo (string grant_type) |
| Returns an OAuth2 login hash. More... | |
| hash< auto > | getOAuth2RefreshInfo () |
| Returns an OAuth2 refresh hash. More... | |
| *hash< auto > | getUpdateOptionsAfterLogin (hash< auto > h) |
| Returns options to update after an OAuth2 login. More... | |
| hash< auto > | loginIntern (*reference< hash< auto > > info) |
| Authenticates with OAuth2 if configured. More... | |
| hash< auto > | oauth2Auth (hash< auto > login, *reference< hash< auto > > info) |
| Perform OAuth2 authentication. More... | |
| nothing | prepareMsg (string method, string path, reference< auto > body, reference< hash< auto > > hdr, string ct='Content-Type') |
| sets up the Content-Type header and encodes any body for sending | |
| nothing | preparePath (reference< string > path) |
| sets up the path for the HTTP request URI | |
| hash< auto > | sendAndDecodeResponse (*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors, *string assume_content_type) |
| sends the outgoing HTTP message and recodes the response to data | |
| setOAuth2LoginInfo (hash< auto > h) | |
| Sets options from the OAuth2 login response on the local object. More... | |
| setupAuth (hash< auto > opts) | |
| Sets up authentication info. More... | |
| AbstractPollOperation | startOAuth2AuthPoll (hash< auto > login) |
| Starts a non-blocking I/O operation to authenticate with an OAuth2 server and acquire an auth token. More... | |
Static Private Member Methods | |
| static | decodeError (hash< auto > h, *reference< hash< auto > > info) |
| decode any REST errors returned if possible | |
Static Private:Internal Member Methods | |
| static | tryDecodeErrorResponse (reference< hash< auto > > h, *reference< hash< auto > > info) |
| tries to decode an error response | |
this class provides the REST client API
| RestClient::RestClient::addDefaultHeaders | ( | hash< auto > | h | ) |
adds default headers to each request
| h | a hash of headers to add to the default headers to send on each request |
Headers added here will be sent in all requests but can be overridden in requests as well.
|
private |
Validates and sets any OAuth2 options.
| RestClient::RestClient::clearConnectionPath | ( | ) |
Clears the connection path when a validator is present that manages the URI path.
Called from the constructor when a REST validator is present that manages the URI path
| RestClient::RestClient::constructor | ( | *hash< auto > | opts, |
| *softbool | do_not_connect | ||
| ) |
calls the base class HTTPClient constructor and optionally connects to the REST server
| opts | valid options are:
|
url: A string giving the URL to connect to; if not given then the target URL will be taken from any validator option, if given by calling AbstractRestSchemaValidator::getTargetUrl()username: The username for authentication; only used if no username or password is set in the URL and if the password option is also usedvalidator: an AbstractRestSchemaValidator object to validate request and response messages; overrides swagger no_charset: if True no charset will be added to the Content-Type header | do_not_connect | if False (the default), then a connection will be immediately established to the remote server |
| RESTCLIENT-ERROR | invalid option passed to constructor, unsupported data serialization, etc |
| hash< auto > RestClient::RestClient::del | ( | string | path, |
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP DELETE request to the REST server and returns the response
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor() |
| info | an optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request; if present the hash will contain the following keys:
|
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
|
private |
Returns the deserialized response body of an OAuth2 authorization / token request.
| hash< auto > RestClient::RestClient::doRequest | ( | string | m, |
| string | path, | ||
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| softbool | decode_errors = True, |
||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP request to the REST server and returns the response
| m | the HTTP method to be used; case is ignored (if not a valid method an HTTP-CLIENT-METHOD-ERROR exception is raised) |
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestCde any content encoding)
|
| decode_errors | decode the message body with HTTP error responses and throw an exception based on the message body |
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| HTTP-CLIENT-METHOD-ERROR | invalid HTTP method argument passed |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
| REST-ACCEPT-ERROR | if the message has a validator that indicates that the response message only supports types not supported by the current options or environment |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
| hash< auto > RestClient::RestClient::doValidatedRequest | ( | string | m, |
| string | path, | ||
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| softbool | decode_errors = True, |
||
| *hash< auto > | hdr | ||
| ) |
The same as doRequest() except no schema validation is performed on the request.
| hash< auto > RestClient::RestClient::get | ( | string | path, |
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP GET request to the REST server and returns the response
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor(); note that sending a message body with an HTTP GET request is not standards compliant; see HTTP GET Requests With a Message Body for more information; for maximum compatibility, use NOTHING for this argument when calling this method |
| info | an optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request; if present the hash will contain the following keys:
|
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
| hash< auto > RestClient::RestClient::getDefaultHeaders | ( | ) |
returns the hash of default headers to sent in all requests
|
private |
Returns headers to use with OAuth2 authorization / token requests.
|
private |
Returns an OAuth2 login hash.
|
private |
Returns an OAuth2 refresh hash.
| *string RestClient::RestClient::getSendEncoding | ( | ) |
returns the current data content encoding (compression) object or NOTHING if no encoding option is set
| string RestClient::RestClient::getSerialization | ( | ) |
returns the current data serialization format currently in effect for the object
| *string RestClient::RestClient::getToken | ( | ) |
Returns any token set for the connection.
| string RestClient::RestClient::getTokenType | ( | ) |
Returns the token type for any token.
|
private |
Returns options to update after an OAuth2 login.
| RestSchemaValidator::AbstractRestSchemaValidator RestClient::RestClient::getValidator | ( | ) |
returns the current validator object
| hash< auto > RestClient::RestClient::gotOAuth2LoginInfo | ( | hash< auto > | h | ) |
Called when OAuth2 login information has been received.
|
private |
Authenticates with OAuth2 if configured.
|
private |
Perform OAuth2 authentication.
| hash< auto > RestClient::RestClient::patch | ( | string | path, |
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP PATCH request to the REST server and returns the response
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor() |
| info | an optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request; if present the hash will contain the following keys:
|
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
| hash< auto > RestClient::RestClient::post | ( | string | path, |
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP POST request to the REST server and returns the response
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor() |
| info | an optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request; if present the hash will contain the following keys:
|
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
| RestClient::RestClient::prepareToSend | ( | string | method, |
| reference< string > | path, | ||
| reference< auto > | body, | ||
| *reference< hash< auto > > | hdr | ||
| ) |
Prepares and processes message parameters for sending without sending the message.
| method | the HTTP method to use @path a reference to the URI path @path body a reference to any message body @path hdr a reference to any headers to send |
| hash< auto > RestClient::RestClient::processRestResponse | ( | hash< auto > | resp, |
| string | method, | ||
| string | path, | ||
| *reference< hash< auto > > | info | ||
| ) |
Process the raw REST response received.
| resp | the return value from HTTPClient::send() |
| method | the HTTP method used |
| path | the URI path used |
| info | an optional info hash reference for information about the call |
| hash< auto > RestClient::RestClient::put | ( | string | path, |
| auto | body, | ||
| *reference< hash< auto > > | info, | ||
| *hash< auto > | hdr | ||
| ) |
sends an HTTP PUT request to the REST server and returns the response
| path | the URI path to add (will be appended to any root path given in the constructor) |
| body | an optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor() |
| info | an optional reference to a hash that will be used as an output variable giving a hash of request headers and other information about the HTTP request; if present the hash will contain the following keys:
|
| hdr | any headers to be sent with the request; headers here will override default headers for the object as well |
"body" key| DESERIALIZATION-ERROR | the response body could not be deserialized (unknown Content-Type or invalid serialization) |
| REST-RESPONSE-ERROR | if this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
error_passthru option is set to True |
Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.
| RestClient::RestClient::replaceDefaultHeaders | ( | *hash< auto > | hdr | ) |
replaces default headers
| hdr | The headers to set; DefaultHeaders will be added to this hash to set the default headers for the object |
| bool RestClient::RestClient::requiresOAuth2Token | ( | ) |
Returns True if the client requires an OAuth2 token.
| RestClient::RestClient::setContentEncoding | ( | string | enc = 'auto' | ) |
sets the request and desired response encoding for the object; see EncodingSupport for valid options
| enc | the data content encoding (compression) option for requests and the desired response content encoding for the object; see EncodingSupport for valid options; if the value "auto" is passed then "gzip" encoding is used for outgoing requests and requested for responses |
| RESTCLIENT-ERROR | invalid or unsupported data content encoding / compression option |
|
private |
Sets options from the OAuth2 login response on the local object.
| RestClient::RestClient::setSendEncoding | ( | string | enc = 'auto' | ) |
change the data content encoding (compression) option for the object
The default is to send requests unencoded/uncompressed.
| enc | the data content encoding (compression) option for the object; see EncodingSupport for valid options; if the value "auto" is passed then "gzip" encoding is used |
| RESTCLIENT-ERROR | invalid or unsupported data content encoding / compression option |
| RestClient::RestClient::setSerialization | ( | string | data = 'auto' | ) |
change the serialization option for the object; see DataSerializationOptions for valid options
| data | the serialization option for the object; see DataSerializationOptions for valid options |
| RESTCLIENT-ERROR | invalid or unsupported serialization option |
| RestClient::RestClient::setToken | ( | string | token_type, |
| string | token, | ||
| *string | refresh_token | ||
| ) |
Sets a token for authentication.
|
private |
Sets up authentication info.
| RestClient::RestClient::setValidator | ( | RestSchemaValidator::AbstractRestSchemaValidator | validator | ) |
Sets a new REST schema validator.
|
private |
Starts a non-blocking I/O operation to authenticate with an OAuth2 server and acquire an auth token.
| AbstractPollOperation RestClient::RestClient::startOAuth2PollRefreshToken | ( | ) |
Starts an OAuth2 refresh token request in a non-blocking I/O operation.
| AbstractPollOperation RestClient::RestClient::startOAuth2PollSendRecv | ( | ) |
Starts an OAuth2 token request in a non-blocking I/O operation.
| bool RestClient::RestClient::usingOAuth2 | ( | ) |
Returns True if the client is configured for authentication with OAuth2.
| const RestClient::RestClient::DataSerializationOptions |
Data serialization options; this is a hash to simulate a set of strings.
Data serialization options are as follows:
"auto": prefers in this order: json, yaml, rawxml, xml, url, and text"bin": for binary message bodies without data serialization"json": use only JSON serialization"rawxml": use raw XML serialization"text": use only plain text. No serialization is used."url": for URL-encoded message bodies"xml": use only XML-RPC serialization"yaml": use only YAML serialization | const RestClient::RestClient::EncodingSupport |
Send content encoding options.
Send content encoding options are as follows:
"bzip": use bzip2 compression"gzip": use gzip compression"deflate": use deflate compression"identity": use no content encoding | const RestClient::RestClient::OAuth2GrantOptions |
Option requirements per OAuth2 grant type.
authorization_code grant type cannot be handled automatically