262 const DataSerializationSupport = {
264 "json": MimeTypeJson,
267 "yaml": MimeTypeYaml,
271 "rawxml": MimeTypeXmlApp,
273 "url": MimeTypeFormUrlEncoded,
274 "text": MimeTypeText,
275 "bin": MimeTypeOctetStream,
278 const DeserializeYaml = {
282 const DeserializeXml = {
285 "in": hash<auto> sub (
string xml, reference<string> type) {
287 on_success type =
"xml";
288 return parse_xmlrpc_value(xml);
289 }
catch (hash<ExceptionInfo> ex) {
291 on_success
type =
"rawxml";
292 return parse_xml(xml);
301 const AcceptList = ...;
305 const Accept = AcceptList.join(
",");
308 const AcceptMap = map {$1: True}, AcceptList;
311 const Version =
"2.0";
317 const DefaultHeaders = {
323 const DefaultOAuth2RedirectUrl =
"auto";
326 const DefaultOptions = {
327 "oauth2_redirect_url": DefaultOAuth2RedirectUrl,
341 const DataSerializationOptions = {
365 const EncodingSupport = {
384 const CompressionThreshold = 1024;
389 const OAuth2GrantOptions = {
390 "authorization_code": (
393 "oauth2_client_secret",
394 "oauth2_redirect_url",
397 "client_credentials": (
399 "oauth2_client_secret",
404 "oauth2_client_secret",
410 const OAuth2AuthHeaders = {
412 # format (ex: the Salesforce OAuth2 server)
413 "Accept": MimeTypeFormUrlEncoded +
"," + MimeTypeJson,
417 const MinimumTokenRefresh = 1m;
461 bool oauth2_auto_refresh = True;
770 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
825 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
880 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
935 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
990 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1022 setToken(
string token_type,
string token, *
string refresh_token);
1095 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1100 hash<auto>
doRequestIntern(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr, *
string assume_content_type);
1112 prepareToSend(
string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1118 hash<auto>
doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1190 hash<auto>
oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1228 nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
string ct =
'Content-Type');
1246 hash<auto>
sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *
string assume_content_type);
1345 "cls": Class::forName(
"RestConnection"),
1346 "options": HttpConnection::ConnectionScheme.options + {
1347 "content_encoding": <ConnectionOptionInfo>{
1349 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1350 "response encoding to request",
1354 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1355 }, <AllowedValueInfo>{
1357 "desc":
"use bzip2 encoding",
1358 }, <AllowedValueInfo>{
1360 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1361 }, <AllowedValueInfo>{
1362 "value":
"identity",
1363 "desc":
"use no content encoding",
1367 "data": <ConnectionOptionInfo>{
1369 "desc":
"data serialization options",
1373 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1374 }, <AllowedValueInfo>{
1376 "desc":
"for binary message bodies without data serialization",
1377 }, <AllowedValueInfo>{
1379 "desc":
"use JSON serialization",
1380 }, <AllowedValueInfo>{
1382 "desc":
"use raw XML serialization",
1383 }, <AllowedValueInfo>{
1385 "desc":
"use only plain text; no serialization is used",
1386 }, <AllowedValueInfo>{
1388 "desc":
"for URL-encoded message bodies",
1389 }, <AllowedValueInfo>{
1391 "desc":
"use only XML-RPC serialization",
1392 }, <AllowedValueInfo>{
1394 "desc":
"use only YAML serialization",
1397 "default_value":
"auto",
1399 "headers": <ConnectionOptionInfo>{
1401 "desc":
"an optional hash of headers to send with every request, these can also be "
1402 "overridden in request method calls",
1404 "oauth2_auth_args": <ConnectionOptionInfo>{
1406 "desc":
"Optional arguments for authentication requests for the `authorization_code` grant type; "
1407 "ignored if the `token` option is set. Note that the `authorization_code` grant type "
1408 "requires external user authorization to acquire an access token",
1410 "oauth2_auth_url": <ConnectionOptionInfo>{
1412 "desc":
"The OAuth2 authorization URL for the `authorization_code` grant type; ignored "
1413 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1414 "external user authorization to acquire an access token",
1416 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1418 "desc":
"If OAuth2 tokens should be automatically refreshed",
1419 "default_value": True,
1421 "oauth2_client_id": <ConnectionOptionInfo>{
1423 "desc":
"The OAuth2 client ID; ignored if the `token` option is set",
1425 "oauth2_client_secret": <ConnectionOptionInfo>{
1427 "desc":
"the OAuth2 client secret; ignored if the `token` option is set",
1430 "oauth2_grant_type": <ConnectionOptionInfo>{
1432 "desc":
"The OAuth2 grant type; ignored if the `token` option is set",
1435 "value":
"authorization_code",
1436 "desc":
"OAuth2 2.0 authorization code grant "
1437 "([RFC 6749 authorization code grant]"
1438 "(https://datatracker.ietf.org/doc/html/rfc6749//section-4.1)); this grant type "
1439 "requires external user authorization to acquire an access token; the "
1440 "`oauth2_auth_url` must be set to inform external code where to request "
1441 "authorization from the external authorization server",
1442 }, <AllowedValueInfo>{
1443 "value":
"client_credentials",
1444 "desc":
"OAuth2 2.0 client credentials grant "
1445 "([RFC 6749 client credentials grant]"
1446 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.4))",
1447 }, <AllowedValueInfo>{
1448 "value":
"password",
1449 "desc":
"OAuth2 2.0 legacy password grant "
1450 "([RFC 6749 password grant]"
1451 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.3))",
1455 "oauth2_redirect_url": <ConnectionOptionInfo>{
1457 "desc":
"The OAuth2 redirect URL for the `authorization_code` grant type; ignored "
1458 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1459 "external user authorization to acquire an access token; the special value `auto` (the "
1460 "default) is meant to be interpreted by servers that implement OAuth2 authorization code "
1462 "default_value":
"auto",
1464 "oauth2_refresh_token": <ConnectionOptionInfo>{
1466 "desc":
"the OAuth2 refresh token, if any (complements option `token`)",
1469 "oauth2_scopes": <ConnectionOptionInfo>{
1471 "desc":
"Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1473 "oauth2_token_url": <ConnectionOptionInfo>{
1475 "desc":
"The token URL for OAuth2 flows; ignored if the `token` option is set",
1477 "password": <ConnectionOptionInfo>{
1479 "desc":
"The password for authentication; only used if no username or password is set in the URL "
1480 "and if the `username` option is also used; conflicts with the `token` option",
1483 "ping_method": <ConnectionOptionInfo>{
1485 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make "
1486 "an HTTP request as a part of the socket polling ping operation; must be a valid HTTP method "
1489 "ping_path": <ConnectionOptionInfo>{
1491 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make "
1492 "an HTTP request as a part of the socket polling ping operation. If the value for this "
1493 "option begins with a `/` character, then it replaces any connection path for the REST "
1494 "client, otherwise the value is appended to the connection path for the REST client.",
1496 "ping_headers": <ConnectionOptionInfo>{
1498 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1499 "one of `ping_method` and `ping_path` are not set",
1501 "ping_body": <ConnectionOptionInfo>{
1503 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1504 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1506 "send_encoding": <ConnectionOptionInfo>{
1508 "desc":
"this sets the send encoding",
1512 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1513 }, <AllowedValueInfo>{
1515 "desc":
"use bzip2 encoding",
1516 }, <AllowedValueInfo>{
1518 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1519 }, <AllowedValueInfo>{
1520 "value":
"identity",
1521 "desc":
"use no content encoding",
1525 "swagger": <ConnectionOptionInfo>{
1526 "type":
"file-as-string",
1527 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1528 "`FileLocationHandler::getTextFileFromLocation()` "
1529 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1532 "swagger_base_path": <ConnectionOptionInfo>{
1534 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1535 "with this option (applies to any REST validator; not just Swagger validators)",
1537 "swagger_lax_parsing": <ConnectionOptionInfo>{
1539 "desc":
"try to parse invalid Swagger schemas",
1541 "token": <ConnectionOptionInfo>{
1543 "desc":
"Any bearer token to use for the connection; will be passed as "
1544 "`Authorization: Bearer ...` in request headers; this option cannot be used with username "
1545 "and password options or authentication information in the URL; if this option is set then "
1546 "OAuth2 options are ignored",
1549 "token_type": <ConnectionOptionInfo>{
1551 "desc":
"The type of `token` to use for the `Authentication` header; ignored if no `token` "
1553 "default_value":
"Bearer",
1555 "username": <ConnectionOptionInfo>{
1557 "desc":
"The username for authentication; only used if no username or password is set in the URL "
1558 "and if the `password` option is also used; conflicts with the `token` option",
1560 "validator": <ConnectionOptionInfo>{
1562 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1610 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
1869 gotOAuth2LoginInfo(hash<auto> h);
*string getToken()
Returns any token set for the connection.
*hash< auto > getUpdateOptionsAfterLogin(hash< auto > h)
Returns options to update after an OAuth2 login.
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
bool usingOAuth2()
Returns True if the client is configured for authentication with OAuth2.
static tryDecodeErrorResponse(reference< hash< auto > > h, *reference< hash< auto > > info)
tries to decode an error response
string oauth2_grant_type
OAuth2 grant type.
Definition: RestClient.qm.dox.h:439
string oauth2_redirect_url
OAuth2 redirect URL.
Definition: RestClient.qm.dox.h:451
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:314
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
hash< auto > loginIntern(*reference< hash< auto > > info)
Authenticates with OAuth2 if configured.
constructor(*hash< auto > opts, *softbool do_not_connect)
calls the base class HTTPClient constructor and optionally connects to the REST server
string token
Any token set for the connection; will be passed as a bearer token (Authorization: Bearer ....
Definition: RestClient.qm.dox.h:457
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
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
checkOAuth2Options(hash< auto > opts)
Validates and sets any OAuth2 options.
setContentEncoding(string enc='auto')
sets the request and desired response encoding for the object; see EncodingSupport for valid options
hash< auto > gotOAuth2LoginInfo(hash< auto > h)
Called when OAuth2 login information has been received.
string oauth2_token_url
OAuth2 token URL.
Definition: RestClient.qm.dox.h:453
nothing preparePath(reference< string > path)
sets up the path for the HTTP request URI
hash< auto > getDefaultHeaders()
returns the hash of default headers to sent in all requests
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
setOAuth2LoginInfo(hash< auto > h)
Sets options from the OAuth2 login response on the local object.
hash< auto > doOAuth2LoginRequest(string url, hash< auto > login, *reference< hash< auto > > info)
Returns the deserialized response body of an OAuth2 authorization / token request.
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.
string getTokenType()
Returns the token type for any token.
setupAuth(hash< auto > opts)
Sets up authentication info.
hash< auto > getOAuth2RefreshInfo()
Returns an OAuth2 refresh hash.
checkLogin(*reference< hash< auto > > info)
Checks if a login is necessary; if so, then the login is performed.
string oauth2_client_id
OAuth2 client ID.
Definition: RestClient.qm.dox.h:441
bool requiresOAuth2Token()
Returns True if the client requires an OAuth2 token.
hash< auto > oauth2Auth(hash< auto > login, *reference< hash< auto > > info)
Perform OAuth2 authentication.
string oauth2_client_secret
OAuth2 client secret.
Definition: RestClient.qm.dox.h:443
string token_type
The token type, if any.
Definition: RestClient.qm.dox.h:455
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
RestSchemaValidator::AbstractRestSchemaValidator getValidator()
returns the current validator object
setSerialization(string data='auto')
change the serialization option for the object; see DataSerializationOptions for valid options
clearConnectionPath()
Clears the connection path when a validator is present that manages the URI path.
setSendEncoding(string enc='auto')
change the data content encoding (compression) option for the object
static decodeError(hash< auto > h, *reference< hash< auto > > info)
decode any REST errors returned if possible
hash< auto > getOAuth2LoginInfo(string grant_type)
Returns an OAuth2 login hash.
AbstractPollOperation startOAuth2AuthPoll(hash< auto > login)
Starts a non-blocking I/O operation to authenticate with an OAuth2 server and acquire an auth token.
AbstractPollOperation startOAuth2PollRefreshToken()
Starts an OAuth2 refresh token request in a non-blocking I/O operation.
hash< auto > processRestResponse(hash< auto > resp, string method, string path, *reference< hash< auto > > info)
Process the raw REST response received.
*softlist< string > oauth2_scopes
OAuth2 scope.
Definition: RestClient.qm.dox.h:445
replaceDefaultHeaders(*hash< auto > hdr)
replaces default headers
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
setToken(string token_type, string token, *string refresh_token)
Sets a token for authentication.
string password
password for authentication
Definition: RestClient.qm.dox.h:436
addDefaultHeaders(hash< auto > h)
adds default headers to each request
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
*hash< auto > getOAuth2AuthHeaders()
Returns headers to use with OAuth2 authorization / token requests.
AbstractPollOperation startOAuth2PollSendRecv()
Starts an OAuth2 token request in a non-blocking I/O operation.
*hash< auto > oauth2_auth_args
OAuth2 extra args.
Definition: RestClient.qm.dox.h:447
string getSerialization()
returns the current data serialization format currently in effect for the object
*string getSendEncoding()
returns the current data content encoding (compression) object or NOTHING if no encoding option is se...
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:311
string oauth2_auth_url
OAuth2 auth URL.
Definition: RestClient.qm.dox.h:449
string refresh_token
Any refresh token granted to the client.
Definition: RestClient.qm.dox.h:459
string username
username for authentication
Definition: RestClient.qm.dox.h:434
prepareToSend(string method, reference< string > path, reference< auto > body, *reference< hash< auto > > hdr)
Prepares and processes message parameters for sending without sending the message.
date token_timestamp
Last timestamp for token acquisition.
Definition: RestClient.qm.dox.h:463
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.
setValidator(RestSchemaValidator::AbstractRestSchemaValidator validator)
Sets a new REST schema validator.
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:1337
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
string getOAuth2OptionName(string opt)
Returns the OAuth2 option name for this connection.
pingImpl()
performs the internal ping
const OptionList
object connection option list
Definition: RestClient.qm.dox.h:1572
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the RestConnection connection object
hash< auto > real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:1341
const Options
object connection options
Definition: RestClient.qm.dox.h:1569
hash< auto > getOAuth2Options()
Returns OAuth2 options in a standard format.
*hash< auto > processOAuth2TokenResponseImpl(hash< auto > resp)
Processes OAuth2 login responses and returns updated options.
string getAuthorizationCodeRequest(hash< AuthCodeInfo > info=< AuthCodeInfo >{})
Returns a URI for an authorization code request.
static softstring getUriValue(auto v)
Returns a value for use as a URI parameter.
const OAuth2AuthRequestOptions
Options required for an OAuth2 authorization request.
Definition: RestClient.qm.dox.h:1575
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
checkAuthCodeFeature()
Sets the auth code feature if supported.
string getAuthUrl(*bool allow_relative)
Returns the OAuth2 authorization URL or throws an exception if not set.
Qore::AbstractPollOperation startPollConnect()
Called to start a non-blocking polling ping operation on the remote REST server.
object getPollImpl()
Returns an unconnected object for a non-blocking poll operation.
*hash< string, bool > getFeaturesImpl()
Returns a list of connection-defined features.
const RCF_OAUTH2_AUTH_CODE
RestClient feature: OAuth2 Auth Code support.
Definition: RestClient.qm.dox.h:1586
hash< auto > processOAuth2TokenResponse(hash< auto > resp)
Processes the OAuth2 token response.
setChildCapabilities()
Sets child data provider capabilities.
RestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a RestClient object
static hash< auto > processOptions(*hash< auto > opts)
processes options for the constructor
hash< auto > getOptions()
gets options
const OAuth2Options
All OAuth2 options.
Definition: RestClient.qm.dox.h:1579
const ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:1344
hash< string, bool > features
Hash of supported features.
Definition: RestClient.qm.dox.h:1590
string getType()
returns "rest"
string getTokenUrl(*bool allow_relative)
Returns the OAuth2 token URL or throws an exception if not set.
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling I/O class with OAuth2 authentication.
Definition: RestClient.qm.dox.h:1780
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition: RestClient.qm.dox.h:1790
*hash< SocketPollInfo > continuePoll()
Returns a hash to be used for I/O polling or NOTHING in case the poll operation is complete.
bool in_refresh
token refresh flag
Definition: RestClient.qm.dox.h:1830
string state
Current state.
Definition: RestClient.qm.dox.h:1824
constructor(RestClient rc, hash< auto > real_opts)
Creates the poller with the REST client and option hash.
string path
The URI path to use.
Definition: RestClient.qm.dox.h:1815
string getGoal()
Returns the goal.
const SPS_OAUTH2_GET_TOKEN
OAuth2 get token state.
Definition: RestClient.qm.dox.h:1787
hash< auto > real_opts
RestClient options.
Definition: RestClient.qm.dox.h:1803
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition: RestClient.qm.dox.h:1784
RestClient rc
The RestClient object to use for polling I/O.
Definition: RestClient.qm.dox.h:1800
const SPS_COMPLETE
Complete state.
Definition: RestClient.qm.dox.h:1796
bool use_path_as_is
Use path directly / ping path already prepared.
Definition: RestClient.qm.dox.h:1833
*hash< auto > headers
Headers to send.
Definition: RestClient.qm.dox.h:1821
const SPS_REST_PING
Execute ping request.
Definition: RestClient.qm.dox.h:1793
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1806
*auto body
The message body to send.
Definition: RestClient.qm.dox.h:1818
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1809
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition: RestClient.qm.dox.h:1812
Mutex m()
Lock for atomicity.
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:239
Hash to use for generating authorization code requests.
Definition: RestClient.qm.dox.h:243
*string redirect_uri
To override the redirect_uri; if not set, the oauth2_redirect_url option will be used instead.
Definition: RestClient.qm.dox.h:248
*list< string > scopes
Scopes to use in the request; if not set, the oauth2_scopes option will be used instead.
Definition: RestClient.qm.dox.h:251
string response_type
The response type value to use in the request.
Definition: RestClient.qm.dox.h:245
*string state
The state value to use in the request.
Definition: RestClient.qm.dox.h:254