270 const DataSerializationSupport = {
272 "json": MimeTypeJson,
275 "yaml": MimeTypeYaml,
279 "rawxml": MimeTypeXmlApp,
281 "url": MimeTypeFormUrlEncoded,
282 "text": MimeTypeText,
283 "bin": MimeTypeOctetStream,
286 const DeserializeYaml = {
290 const DeserializeXml = {
293 "in": hash<auto> sub (
string xml, reference<string> type) {
295 on_success type =
"xml";
296 return parse_xmlrpc_value(xml);
297 }
catch (hash<ExceptionInfo> ex) {
299 on_success
type =
"rawxml";
300 return parse_xml(xml);
309 const AcceptList = ...;
313 const Accept = AcceptList.join(
",");
316 const AcceptMap = map {$1: True}, AcceptList;
319 const Version =
"2.0";
325 const DefaultHeaders = {
331 const DefaultOAuth2RedirectUrl =
"auto";
334 const DefaultOptions = {
335 "oauth2_redirect_url": DefaultOAuth2RedirectUrl,
349 const DataSerializationOptions = {
373 const EncodingSupport = {
392 const CompressionThreshold = 1024;
397 const OAuth2GrantOptions = {
398 "authorization_code": (
401 "oauth2_client_secret",
402 "oauth2_redirect_url",
405 "client_credentials": (
407 "oauth2_client_secret",
412 "oauth2_client_secret",
418 const OAuth2AuthHeaders = {
420 # format (ex: the Salesforce OAuth2 server)
421 "Accept": MimeTypeFormUrlEncoded +
"," + MimeTypeJson,
425 const MinimumTokenRefresh = 1m;
469 bool oauth2_auto_refresh = True;
778 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
833 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
888 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
943 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
998 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1030 setToken(
string token_type,
string token, *
string refresh_token);
1103 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1108 hash<auto>
doRequestIntern(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr, *
string assume_content_type);
1120 prepareToSend(
string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1126 hash<auto>
doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1198 hash<auto>
oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1236 nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
string ct =
'Content-Type');
1254 hash<auto>
sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *
string assume_content_type);
1353 "cls": Class::forName(
"RestConnection"),
1354 "options": HttpConnection::ConnectionScheme.options + {
1355 "content_encoding": <ConnectionOptionInfo>{
1357 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1358 "response encoding to request",
1362 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1363 }, <AllowedValueInfo>{
1365 "desc":
"use bzip2 encoding",
1366 }, <AllowedValueInfo>{
1368 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1369 }, <AllowedValueInfo>{
1370 "value":
"identity",
1371 "desc":
"use no content encoding",
1375 "data": <ConnectionOptionInfo>{
1377 "desc":
"data serialization options",
1381 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1382 }, <AllowedValueInfo>{
1384 "desc":
"for binary message bodies without data serialization",
1385 }, <AllowedValueInfo>{
1387 "desc":
"use JSON serialization",
1388 }, <AllowedValueInfo>{
1390 "desc":
"use raw XML serialization",
1391 }, <AllowedValueInfo>{
1393 "desc":
"use only plain text; no serialization is used",
1394 }, <AllowedValueInfo>{
1396 "desc":
"for URL-encoded message bodies",
1397 }, <AllowedValueInfo>{
1399 "desc":
"use only XML-RPC serialization",
1400 }, <AllowedValueInfo>{
1402 "desc":
"use only YAML serialization",
1405 "default_value":
"auto",
1407 "headers": <ConnectionOptionInfo>{
1409 "desc":
"an optional hash of headers to send with every request, these can also be "
1410 "overridden in request method calls",
1412 "oauth2_auth_args": <ConnectionOptionInfo>{
1414 "desc":
"Optional arguments for authentication requests for the `authorization_code` grant type; "
1415 "ignored if the `token` option is set. Note that the `authorization_code` grant type "
1416 "requires external user authorization to acquire an access token",
1418 "oauth2_auth_url": <ConnectionOptionInfo>{
1420 "desc":
"The OAuth2 authorization URL for the `authorization_code` grant type; ignored "
1421 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1422 "external user authorization to acquire an access token",
1424 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1426 "desc":
"If OAuth2 tokens should be automatically refreshed",
1427 "default_value": True,
1429 "oauth2_client_id": <ConnectionOptionInfo>{
1431 "desc":
"The OAuth2 client ID; ignored if the `token` option is set",
1433 "oauth2_client_secret": <ConnectionOptionInfo>{
1435 "desc":
"the OAuth2 client secret; ignored if the `token` option is set",
1438 "oauth2_grant_type": <ConnectionOptionInfo>{
1440 "desc":
"The OAuth2 grant type; ignored if the `token` option is set",
1443 "value":
"authorization_code",
1444 "desc":
"OAuth2 2.0 authorization code grant "
1445 "([RFC 6749 authorization code grant]"
1446 "(https://datatracker.ietf.org/doc/html/rfc6749//section-4.1)); this grant type "
1447 "requires external user authorization to acquire an access token; the "
1448 "`oauth2_auth_url` must be set to inform external code where to request "
1449 "authorization from the external authorization server",
1450 }, <AllowedValueInfo>{
1451 "value":
"client_credentials",
1452 "desc":
"OAuth2 2.0 client credentials grant "
1453 "([RFC 6749 client credentials grant]"
1454 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.4))",
1455 }, <AllowedValueInfo>{
1456 "value":
"password",
1457 "desc":
"OAuth2 2.0 legacy password grant "
1458 "([RFC 6749 password grant]"
1459 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.3))",
1463 "oauth2_redirect_url": <ConnectionOptionInfo>{
1465 "desc":
"The OAuth2 redirect URL for the `authorization_code` grant type; ignored "
1466 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1467 "external user authorization to acquire an access token; the special value `auto` (the "
1468 "default) is meant to be interpreted by servers that implement OAuth2 authorization code "
1470 "default_value":
"auto",
1472 "oauth2_refresh_token": <ConnectionOptionInfo>{
1474 "desc":
"the OAuth2 refresh token, if any (complements option `token`)",
1477 "oauth2_scopes": <ConnectionOptionInfo>{
1479 "desc":
"Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1481 "oauth2_token_url": <ConnectionOptionInfo>{
1483 "desc":
"The token URL for OAuth2 flows; ignored if the `token` option is set",
1485 "password": <ConnectionOptionInfo>{
1487 "desc":
"The password for authentication; only used if no username or password is set in the URL "
1488 "and if the `username` option is also used; conflicts with the `token` option",
1491 "ping_method": <ConnectionOptionInfo>{
1493 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make "
1494 "an HTTP request as a part of the socket polling ping operation; must be a valid HTTP method "
1497 "ping_path": <ConnectionOptionInfo>{
1499 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make "
1500 "an HTTP request as a part of the socket polling ping operation. If the value for this "
1501 "option begins with a `/` character, then it replaces any connection path for the REST "
1502 "client, otherwise the value is appended to the connection path for the REST client.",
1504 "ping_headers": <ConnectionOptionInfo>{
1506 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1507 "one of `ping_method` and `ping_path` are not set",
1509 "ping_body": <ConnectionOptionInfo>{
1511 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1512 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1514 "send_encoding": <ConnectionOptionInfo>{
1516 "desc":
"this sets the send encoding",
1520 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1521 }, <AllowedValueInfo>{
1523 "desc":
"use bzip2 encoding",
1524 }, <AllowedValueInfo>{
1526 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1527 }, <AllowedValueInfo>{
1528 "value":
"identity",
1529 "desc":
"use no content encoding",
1533 "swagger": <ConnectionOptionInfo>{
1534 "type":
"file-as-string",
1535 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1536 "`FileLocationHandler::getTextFileFromLocation()` "
1537 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1540 "swagger_base_path": <ConnectionOptionInfo>{
1542 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1543 "with this option (applies to any REST validator; not just Swagger validators)",
1545 "swagger_lax_parsing": <ConnectionOptionInfo>{
1547 "desc":
"try to parse invalid Swagger schemas",
1549 "token": <ConnectionOptionInfo>{
1551 "desc":
"Any bearer token to use for the connection; will be passed as "
1552 "`Authorization: Bearer ...` in request headers; this option cannot be used with username "
1553 "and password options or authentication information in the URL; if this option is set then "
1554 "OAuth2 options are ignored",
1557 "token_type": <ConnectionOptionInfo>{
1559 "desc":
"The type of `token` to use for the `Authentication` header; ignored if no `token` "
1561 "default_value":
"Bearer",
1563 "username": <ConnectionOptionInfo>{
1565 "desc":
"The username for authentication; only used if no username or password is set in the URL "
1566 "and if the `password` option is also used; conflicts with the `token` option",
1568 "validator": <ConnectionOptionInfo>{
1570 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1618 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
1889 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:447
string oauth2_redirect_url
OAuth2 redirect URL.
Definition: RestClient.qm.dox.h:459
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:322
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:465
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:461
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:449
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:451
string token_type
The token type, if any.
Definition: RestClient.qm.dox.h:463
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:453
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:444
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:455
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:319
string oauth2_auth_url
OAuth2 auth URL.
Definition: RestClient.qm.dox.h:457
string refresh_token
Any refresh token granted to the client.
Definition: RestClient.qm.dox.h:467
string username
username for authentication
Definition: RestClient.qm.dox.h:442
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:471
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:1345
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:1580
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the RestConnection connection object
string getUrlOption(string opt, *bool allow_relative)
Returns the value of a URL option or throws an exception if not set.
hash< auto > real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:1349
const Options
object connection options
Definition: RestClient.qm.dox.h:1577
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:1583
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:1594
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:1587
const ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:1352
hash< string, bool > features
Hash of supported features.
Definition: RestClient.qm.dox.h:1598
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:1800
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition: RestClient.qm.dox.h:1810
*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:1850
string state
Current state.
Definition: RestClient.qm.dox.h:1844
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:1835
string getGoal()
Returns the goal.
const SPS_OAUTH2_GET_TOKEN
OAuth2 get token state.
Definition: RestClient.qm.dox.h:1807
hash< auto > real_opts
RestClient options.
Definition: RestClient.qm.dox.h:1823
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition: RestClient.qm.dox.h:1804
RestClient rc
The RestClient object to use for polling I/O.
Definition: RestClient.qm.dox.h:1820
const SPS_COMPLETE
Complete state.
Definition: RestClient.qm.dox.h:1816
bool use_path_as_is
Use path directly / ping path already prepared.
Definition: RestClient.qm.dox.h:1853
*hash< auto > headers
Headers to send.
Definition: RestClient.qm.dox.h:1841
const SPS_REST_PING
Execute ping request.
Definition: RestClient.qm.dox.h:1813
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1826
*auto body
The message body to send.
Definition: RestClient.qm.dox.h:1838
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1829
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition: RestClient.qm.dox.h:1832
Mutex m()
Lock for atomicity.
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:247
Hash to use for generating authorization code requests.
Definition: RestClient.qm.dox.h:251
*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:256
*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:259
string response_type
The response type value to use in the request.
Definition: RestClient.qm.dox.h:253
*string state
The state value to use in the request.
Definition: RestClient.qm.dox.h:262