258 const DataSerializationSupport = {
260 "json": MimeTypeJson,
263 "yaml": MimeTypeYaml,
267 "rawxml": MimeTypeXmlApp,
269 "url": MimeTypeFormUrlEncoded,
270 "text": MimeTypeText,
271 "bin": MimeTypeOctetStream,
274 const DeserializeYaml = {
278 const DeserializeXml = {
281 "in": hash<auto> sub (
string xml, reference<string> type) {
283 on_success type =
"xml";
284 return parse_xmlrpc_value(xml);
285 }
catch (hash<ExceptionInfo> ex) {
287 on_success
type =
"rawxml";
288 return parse_xml(xml);
297 const AcceptList = ...;
301 const Accept = AcceptList.join(
",");
304 const AcceptMap = map {$1: True}, AcceptList;
307 const Version =
"2.0";
313 const DefaultHeaders = {
319 const DefaultOAuth2RedirectUri =
"auto";
322 const DefaultOptions = {
323 "oauth2_redirect_uri": DefaultOAuth2RedirectUri,
337 const DataSerializationOptions = {
361 const EncodingSupport = {
380 const CompressionThreshold = 1024;
385 const OAuth2GrantOptions = {
386 "authorization_code": (
389 "oauth2_client_secret",
390 "oauth2_redirect_url",
393 "client_credentials": (
395 "oauth2_client_secret",
400 "oauth2_client_secret",
406 const OAuth2AuthHeaders = {
408 # format (ex: the Salesforce OAuth2 server)
409 "Accept": MimeTypeFormUrlEncoded +
"," + MimeTypeJson,
454 bool oauth2_auto_refresh = True;
761 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
816 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
871 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
926 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
981 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
1013 setToken(
string token_type,
string token, *
string refresh_token);
1086 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1091 hash<auto>
doRequestIntern(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr, *
string assume_content_type);
1103 prepareToSend(
string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1109 hash<auto>
doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1181 hash<auto>
oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1219 nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
string ct =
'Content-Type');
1237 hash<auto>
sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *
string assume_content_type);
1336 "cls": Class::forName(
"RestConnection"),
1337 "options": HttpConnection::ConnectionScheme.options + {
1338 "content_encoding": <ConnectionOptionInfo>{
1340 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1341 "response encoding to request",
1345 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1346 }, <AllowedValueInfo>{
1348 "desc":
"use bzip2 encoding",
1349 }, <AllowedValueInfo>{
1351 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1352 }, <AllowedValueInfo>{
1353 "value":
"identity",
1354 "desc":
"use no content encoding",
1358 "data": <ConnectionOptionInfo>{
1360 "desc":
"data serialization options",
1364 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1365 }, <AllowedValueInfo>{
1367 "desc":
"for binary message bodies without data serialization",
1368 }, <AllowedValueInfo>{
1370 "desc":
"use JSON serialization",
1371 }, <AllowedValueInfo>{
1373 "desc":
"use raw XML serialization",
1374 }, <AllowedValueInfo>{
1376 "desc":
"use only plain text; no serialization is used",
1377 }, <AllowedValueInfo>{
1379 "desc":
"for URL-encoded message bodies",
1380 }, <AllowedValueInfo>{
1382 "desc":
"use only XML-RPC serialization",
1383 }, <AllowedValueInfo>{
1385 "desc":
"use only YAML serialization",
1388 "default_value":
"auto",
1390 "headers": <ConnectionOptionInfo>{
1392 "desc":
"an optional hash of headers to send with every request, these can also be "
1393 "overridden in request method calls",
1395 "oauth2_auth_args": <ConnectionOptionInfo>{
1397 "desc":
"Optional arguments for authentication requests for the `authorization_code` grant type; "
1398 "ignored if the `token` option is set. Note that the `authorization_code` grant type "
1399 "requires external user authorization to acquire an access token",
1401 "oauth2_auth_url": <ConnectionOptionInfo>{
1403 "desc":
"The OAuth2 authorization URL for the `authorization_code` grant type; ignored "
1404 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1405 "external user authorization to acquire an access token",
1407 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1409 "desc":
"If OAuth2 tokens should be automatically refreshed",
1410 "default_value": True,
1412 "oauth2_client_id": <ConnectionOptionInfo>{
1414 "desc":
"The OAuth2 client ID; ignored if the `token` option is set",
1416 "oauth2_client_secret": <ConnectionOptionInfo>{
1418 "desc":
"the OAuth2 client secret; ignored if the `token` option is set",
1421 "oauth2_grant_type": <ConnectionOptionInfo>{
1423 "desc":
"The OAuth2 grant type; ignored if the `token` option is set",
1426 "value":
"authorization_code",
1427 "desc":
"OAuth2 2.0 authorization code grant "
1428 "([RFC 6749 authorization code grant]"
1429 "(https://datatracker.ietf.org/doc/html/rfc6749//section-4.1)); this grant type "
1430 "requires external user authorization to acquire an access token; the "
1431 "`oauth2_auth_url` must be set to inform external code where to request "
1432 "authorization from the external authorization server",
1433 }, <AllowedValueInfo>{
1434 "value":
"client_credentials",
1435 "desc":
"OAuth2 2.0 client credentials grant "
1436 "([RFC 6749 client credentials grant]"
1437 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.4))",
1438 }, <AllowedValueInfo>{
1439 "value":
"password",
1440 "desc":
"OAuth2 2.0 legacy password grant "
1441 "([RFC 6749 password grant]"
1442 "(https://datatracker.ietf.org/doc/html/rfc6749#section-1.3.3))",
1446 "oauth2_redirect_url": <ConnectionOptionInfo>{
1448 "desc":
"The OAuth2 redirect URL for the `authorization_code` grant type; ignored "
1449 "if the `token` option is set. Note that the `authorization_code` grant type requires "
1450 "external user authorization to acquire an access token; the special value \c \"auto\" (the "
1451 "default) is meant to be interpreted by servers that implement OAuth2 authorization code "
1453 "default_value":
"auto",
1455 "oauth2_refresh_token": <ConnectionOptionInfo>{
1457 "desc":
"the OAuth2 refresh token, if any (complements option `token`)",
1460 "oauth2_scopes": <ConnectionOptionInfo>{
1462 "desc":
"Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1464 "oauth2_token_url": <ConnectionOptionInfo>{
1466 "desc":
"The token URL for OAuth2 flows; ignored if the `token` option is set",
1468 "password": <ConnectionOptionInfo>{
1470 "desc":
"The password for authentication; only used if no username or password is set in the URL "
1471 "and if the `username` option is also used; conflicts with the `token` option",
1474 "ping_method": <ConnectionOptionInfo>{
1476 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make "
1477 "an HTTP request as a part of the socket polling ping operation; must be a valid HTTP method "
1480 "ping_path": <ConnectionOptionInfo>{
1482 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make "
1483 "an HTTP request as a part of the socket polling ping operation. If the value for this "
1484 "option begins with a `/` character, then it replaces any connection path for the REST "
1485 "client, otherwise the value is appended to the connection path for the REST client.",
1487 "ping_headers": <ConnectionOptionInfo>{
1489 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1490 "one of `ping_method` and `ping_path` are not set",
1492 "ping_body": <ConnectionOptionInfo>{
1494 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1495 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1497 "send_encoding": <ConnectionOptionInfo>{
1499 "desc":
"this sets the send encoding",
1503 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1504 }, <AllowedValueInfo>{
1506 "desc":
"use bzip2 encoding",
1507 }, <AllowedValueInfo>{
1509 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1510 }, <AllowedValueInfo>{
1511 "value":
"identity",
1512 "desc":
"use no content encoding",
1516 "swagger": <ConnectionOptionInfo>{
1517 "type":
"file-as-string",
1518 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1519 "`FileLocationHandler::getTextFileFromLocation()` "
1520 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1523 "swagger_base_path": <ConnectionOptionInfo>{
1525 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1526 "with this option (applies to any REST validator; not just Swagger validators)",
1528 "swagger_lax_parsing": <ConnectionOptionInfo>{
1530 "desc":
"try to parse invalid Swagger schemas",
1532 "token": <ConnectionOptionInfo>{
1534 "desc":
"Any bearer token to use for the connection; will be passed as "
1535 "`Authorization: Bearer ...` in request headers; this option cannot be used with username "
1536 "and password options or authentication information in the URL; if this option is set then "
1537 "OAuth2 options are ignored",
1540 "token_type": <ConnectionOptionInfo>{
1542 "desc":
"The type of `token` to use for the `Authentication` header; ignored if no `token` "
1544 "default_value":
"Bearer",
1546 "username": <ConnectionOptionInfo>{
1548 "desc":
"The username for authentication; only used if no username or password is set in the URL "
1549 "and if the `password` option is also used; conflicts with the `token` option",
1551 "validator": <ConnectionOptionInfo>{
1553 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1601 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
1860 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:432
string oauth2_redirect_url
OAuth2 redirect URL.
Definition: RestClient.qm.dox.h:444
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:310
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:450
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:446
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:434
bool requiresOAuth2Token()
Returns True if the client requires an OAuth2 token.
hash< auto > oauth2Auth(hash< auto > login, *reference< hash< auto > > info)
Perform OAuth2 password authentication.
string oauth2_client_secret
OAuth2 client secret.
Definition: RestClient.qm.dox.h:436
string token_type
The token type, if any.
Definition: RestClient.qm.dox.h:448
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:438
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:429
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:440
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:307
string oauth2_auth_url
OAuth2 auth URL.
Definition: RestClient.qm.dox.h:442
string refresh_token
Any refresh token granted to the client.
Definition: RestClient.qm.dox.h:452
string username
username for authentication
Definition: RestClient.qm.dox.h:427
prepareToSend(string method, reference< string > path, reference< auto > body, *reference< hash< auto > > hdr)
Prepares and processes message parameters for sending without sending the message.
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:1328
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:1563
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:1332
const Options
object connection options
Definition: RestClient.qm.dox.h:1560
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:1566
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:1577
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:1570
const ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:1335
hash< string, bool > features
Hash of supported features.
Definition: RestClient.qm.dox.h:1581
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:1771
const SPS_OAUTH2_REFRESH_TOKEN
OAuth2 refresh token state.
Definition: RestClient.qm.dox.h:1781
*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:1821
string state
Current state.
Definition: RestClient.qm.dox.h:1815
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:1806
string getGoal()
Returns the goal.
const SPS_OAUTH2_GET_TOKEN
OAuth2 get token state.
Definition: RestClient.qm.dox.h:1778
hash< auto > real_opts
RestClient options.
Definition: RestClient.qm.dox.h:1794
const SPS_GET_SWAGGER
Retrieve Swagger schema.
Definition: RestClient.qm.dox.h:1775
RestClient rc
The RestClient object to use for polling I/O.
Definition: RestClient.qm.dox.h:1791
const SPS_COMPLETE
Complete state.
Definition: RestClient.qm.dox.h:1787
bool use_path_as_is
Use path directly / ping path already prepared.
Definition: RestClient.qm.dox.h:1824
*hash< auto > headers
Headers to send.
Definition: RestClient.qm.dox.h:1812
const SPS_REST_PING
Execute ping request.
Definition: RestClient.qm.dox.h:1784
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1797
*auto body
The message body to send.
Definition: RestClient.qm.dox.h:1809
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1800
string getState()
Returns the current state.
string method
The HTTP method to use.
Definition: RestClient.qm.dox.h:1803
Mutex m()
Lock for atomicity.
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:235
Hash to use for generating authorization code requests.
Definition: RestClient.qm.dox.h:239
*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:244
*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:247
string response_type
The response type value to use in the request.
Definition: RestClient.qm.dox.h:241
*string state
The state value to use in the request.
Definition: RestClient.qm.dox.h:250