Qore RestClient Module Reference 2.0
Loading...
Searching...
No Matches
RestClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* RestClient.qm Copyright (C) 2013 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum qore version
26
27// require type definitions everywhere
28
29// enable all warnings
30
31// don't use "$" for vars, members, and methods, assume local variable scope
32
33
34
35
36
37
38
39/* Version History - see below in docs
40*/
41
235namespace RestClient {
237
239public hashdecl AuthCodeInfo {
241 string response_type = "code";
242
245
247 *list<string> scopes;
248
250 *string state;
251};
252
254class RestClient : public Qore::HTTPClient, public Logger::LoggerWrapper, public ConnectionProvider::UpdateOptionsInterface {
255
256public:
258 const DataSerializationSupport = {
259%ifndef NoJson
260 "json": MimeTypeJson,
261%endif
262%ifndef NoYaml
263 "yaml": MimeTypeYaml,
264%endif
265%ifndef NoXml
266 "xml": MimeTypeXml,
267 "rawxml": MimeTypeXmlApp,
268%endif
269 "url": MimeTypeFormUrlEncoded,
270 "text": MimeTypeText,
271 "bin": MimeTypeOctetStream,
272 };
273
274 const DeserializeYaml = {
275 "code": "yaml",
276 "in": \parse_yaml(),
277 };
278 const DeserializeXml = {
279 "code": "xml",
280 "arg": True,
281 "in": hash<auto> sub (string xml, reference<string> type) {
282 try {
283 on_success type = "xml";
284 return parse_xmlrpc_value(xml);
285 } catch (hash<ExceptionInfo> ex) {
286 try {
287 on_success type = "rawxml";
288 return parse_xml(xml);
289 } catch () {
290 rethrow;
291 }
292 }
293 },
294 };
295
297 const AcceptList = ...;
298
299
301 const Accept = AcceptList.join(",");
302
304 const AcceptMap = map {$1: True}, AcceptList;
305
307 const Version = "2.0";
308
310 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
311
313 const DefaultHeaders = {
314 "Accept": Accept,
315 "User-Agent": RestClient::VersionString,
316 };
317
319 const DefaultOAuth2RedirectUri = "auto";
320
322 const DefaultOptions = {
323 "oauth2_redirect_uri": DefaultOAuth2RedirectUri,
324 };
325
327
337 const DataSerializationOptions = {
338 "auto": True,
339%ifndef NoJson
340 "json": True,
341%endif
342%ifndef NoYaml
343 "yaml": True,
344%endif
345%ifndef NoXml
346 "rawxml": True,
347 "xml": True,
348%endif
349 "url": True,
350 "text": True,
351 "bin": True,
352 };
353
355
361 const EncodingSupport = {
362 "gzip": {
363 "ce": "gzip",
364 "func": \gzip(),
365 },
366 "bzip2": {
367 "ce": "bzip2",
368 "func": \bzip2(),
369 },
370 "deflate": {
371 "ce": "deflate",
372 "func": \compress(),
373 },
374 "identity": {
375 "ce": NOTHING,
376 },
377 };
378
380 const CompressionThreshold = 1024;
381
383
385 const OAuth2GrantOptions = {
386 "authorization_code": (
387 "oauth2_auth_url",
388 "oauth2_client_id",
389 "oauth2_client_secret",
390 "oauth2_redirect_url",
391 "oauth2_token_url",
392 ),
393 "client_credentials": (
394 "oauth2_client_id",
395 "oauth2_client_secret",
396 "oauth2_token_url",
397 ),
398 "password": (
399 "oauth2_client_id",
400 "oauth2_client_secret",
401 "oauth2_token_url",
402 ),
403 };
404
406 const OAuth2AuthHeaders = {
407 // this will ensure that OAuth2 servers do not prefer XML or other serialization with a different data
408 # format (ex: the Salesforce OAuth2 server)
409 "Accept": MimeTypeFormUrlEncoded + "," + MimeTypeJson,
410 };
411
412protected:
413 // headers to send with every request
414 hash<auto> headers;
415 // data serialization code
416 string ds;
417 // serialization content type
418 string sct;
419 // send content encoding hash
420 *hash<auto> seh;
421 // REST schema validator
423 // no_charset option
424 *bool noCharset;
425
427 string username;
429 string password;
430
438 *softlist<string> oauth2_scopes;
440 *hash<auto> oauth2_auth_args;
450 string token;
454 bool oauth2_auto_refresh = True;
455
456public:
457
459
557 constructor(*hash<auto> opts, *softbool do_not_connect) ;
558
559
561
564
565
567
580 setSerialization(string data = 'auto');
581
582
584
601 setSendEncoding(string enc = 'auto');
602
603
605
622 setContentEncoding(string enc = 'auto');
623
624
626
642 addDefaultHeaders(hash<auto> h);
643
644
646
659 hash<auto> getDefaultHeaders();
660
661
663
668 replaceDefaultHeaders(*hash<auto> hdr);
669
670
672
688
689
691
704
705
707
761 hash<auto> get(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
762
763
765
816 hash<auto> put(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
817
818
820
871 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
872
873
875
926 hash<auto> post(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
927
928
930
981 hash<auto> del(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
982
983
985
990
991
993
996
997
999
1002
1003
1005
1008
1009
1011
1013 setToken(string token_type, string token, *string refresh_token);
1014
1015
1017
1020
1021
1023
1025 *string getToken();
1026
1027
1029
1031 AbstractPollOperation startOAuth2PollSendRecv();
1032
1033
1035
1037 AbstractPollOperation startOAuth2PollRefreshToken();
1038
1039
1041
1086 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1087
1088
1090protected:
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);
1092public:
1093
1094
1096
1103 prepareToSend(string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1104
1105
1107
1109 hash<auto> doValidatedRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1110
1111
1113
1120 hash<auto> processRestResponse(hash<auto> resp, string method, string path, *reference<hash<auto>> info);
1121
1122
1124
1126 hash<auto> gotOAuth2LoginInfo(hash<auto> h);
1127
1128
1130
1132protected:
1133 setOAuth2LoginInfo(hash<auto> h);
1134public:
1135
1136
1138
1140protected:
1141 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h);
1142public:
1143
1144
1146
1148protected:
1149 setupAuth(hash<auto> opts);
1150public:
1151
1152
1154
1156protected:
1157 checkOAuth2Options(hash<auto> opts);
1158public:
1159
1160
1162
1164protected:
1165 hash<auto> loginIntern(*reference<hash<auto>> info);
1166public:
1167
1168
1170
1172protected:
1173 AbstractPollOperation startOAuth2AuthPoll(hash<auto> login);
1174public:
1175
1176
1178
1180protected:
1181 hash<auto> oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1182public:
1183
1184
1186
1188protected:
1189 hash<auto> doOAuth2LoginRequest(string url, hash<auto> login, *reference<hash<auto>> info);
1190public:
1191
1192
1194
1196protected:
1198public:
1199
1200
1202
1204protected:
1205 hash<auto> getOAuth2LoginInfo(string grant_type);
1206public:
1207
1208
1210
1212protected:
1214public:
1215
1216
1218protected:
1219 nothing prepareMsg(string method, string path, reference<auto> body, reference<hash<auto>> hdr, string ct = 'Content-Type');
1220public:
1221
1222
1224protected:
1225 nothing preparePath(reference<string> path);
1226public:
1227
1228
1230protected:
1231 checkLogin(*reference<hash<auto>> info);
1232public:
1233
1234
1236protected:
1237 hash<auto> sendAndDecodeResponse(*data body, string m, string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *string assume_content_type);
1238public:
1239
1240
1242protected:
1243 static decodeError(hash<auto> h, *reference<hash<auto>> info);
1244public:
1245
1246
1248private:
1249 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1250public:
1251
1252
1253}; // class RestClient
1254
1256
1329
1330public:
1332 hash<auto> real_opts;
1333
1335 const ConnectionScheme = <ConnectionSchemeInfo>{
1336 "cls": Class::forName("RestConnection"),
1337 "options": HttpConnection::ConnectionScheme.options + {
1338 "content_encoding": <ConnectionOptionInfo>{
1339 "type": "string",
1340 "desc": "this sets the send encoding (if the `send_encoding` option is not set) and the "
1341 "response encoding to request",
1342 "allowed_values": (
1343 <AllowedValueInfo>{
1344 "value": "gzip",
1345 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1346 }, <AllowedValueInfo>{
1347 "value": "bzip2",
1348 "desc": "use bzip2 encoding",
1349 }, <AllowedValueInfo>{
1350 "value": "deflate",
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",
1355 },
1356 ),
1357 },
1358 "data": <ConnectionOptionInfo>{
1359 "type": "string",
1360 "desc": "data serialization options",
1361 "allowed_values": (
1362 <AllowedValueInfo>{
1363 "value": "auto",
1364 "desc": "prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1365 }, <AllowedValueInfo>{
1366 "value": "bin",
1367 "desc": "for binary message bodies without data serialization",
1368 }, <AllowedValueInfo>{
1369 "value": "json",
1370 "desc": "use JSON serialization",
1371 }, <AllowedValueInfo>{
1372 "value": "rawxml",
1373 "desc": "use raw XML serialization",
1374 }, <AllowedValueInfo>{
1375 "value": "text",
1376 "desc": "use only plain text; no serialization is used",
1377 }, <AllowedValueInfo>{
1378 "value": "url",
1379 "desc": "for URL-encoded message bodies",
1380 }, <AllowedValueInfo>{
1381 "value": "xml",
1382 "desc": "use only XML-RPC serialization",
1383 }, <AllowedValueInfo>{
1384 "value": "yaml",
1385 "desc": "use only YAML serialization",
1386 },
1387 ),
1388 "default_value": "auto",
1389 },
1390 "headers": <ConnectionOptionInfo>{
1391 "type": "hash",
1392 "desc": "an optional hash of headers to send with every request, these can also be "
1393 "overridden in request method calls",
1394 },
1395 "oauth2_auth_args": <ConnectionOptionInfo>{
1396 "type": "hash",
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",
1400 },
1401 "oauth2_auth_url": <ConnectionOptionInfo>{
1402 "type": "string",
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",
1406 },
1407 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1408 "type": "bool",
1409 "desc": "If OAuth2 tokens should be automatically refreshed",
1410 "default_value": True,
1411 },
1412 "oauth2_client_id": <ConnectionOptionInfo>{
1413 "type": "string",
1414 "desc": "The OAuth2 client ID; ignored if the `token` option is set",
1415 },
1416 "oauth2_client_secret": <ConnectionOptionInfo>{
1417 "type": "string",
1418 "desc": "the OAuth2 client secret; ignored if the `token` option is set",
1419 "sensitive": True,
1420 },
1421 "oauth2_grant_type": <ConnectionOptionInfo>{
1422 "type": "string",
1423 "desc": "The OAuth2 grant type; ignored if the `token` option is set",
1424 "allowed_values": (
1425 <AllowedValueInfo>{
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))",
1443 },
1444 ),
1445 },
1446 "oauth2_redirect_url": <ConnectionOptionInfo>{
1447 "type": "string",
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 "
1452 "client handling",
1453 "default_value": "auto",
1454 },
1455 "oauth2_refresh_token": <ConnectionOptionInfo>{
1456 "type": "string",
1457 "desc": "the OAuth2 refresh token, if any (complements option `token`)",
1458 "sensitive": True,
1459 },
1460 "oauth2_scopes": <ConnectionOptionInfo>{
1461 "type": "list",
1462 "desc": "Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1463 },
1464 "oauth2_token_url": <ConnectionOptionInfo>{
1465 "type": "string",
1466 "desc": "The token URL for OAuth2 flows; ignored if the `token` option is set",
1467 },
1468 "password": <ConnectionOptionInfo>{
1469 "type": "string",
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",
1472 "sensitive": True,
1473 },
1474 "ping_method": <ConnectionOptionInfo>{
1475 "type": "string",
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 "
1478 "name",
1479 },
1480 "ping_path": <ConnectionOptionInfo>{
1481 "type": "string",
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.",
1486 },
1487 "ping_headers": <ConnectionOptionInfo>{
1488 "type": "hash",
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",
1491 },
1492 "ping_body": <ConnectionOptionInfo>{
1493 "type": "any",
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`",
1496 },
1497 "send_encoding": <ConnectionOptionInfo>{
1498 "type": "string",
1499 "desc": "this sets the send encoding",
1500 "allowed_values": (
1501 <AllowedValueInfo>{
1502 "value": "gzip",
1503 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1504 }, <AllowedValueInfo>{
1505 "value": "bzip2",
1506 "desc": "use bzip2 encoding",
1507 }, <AllowedValueInfo>{
1508 "value": "deflate",
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",
1513 },
1514 ),
1515 },
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`",
1521 "freeform": True,
1522 },
1523 "swagger_base_path": <ConnectionOptionInfo>{
1524 "type": "string",
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)",
1527 },
1528 "swagger_lax_parsing": <ConnectionOptionInfo>{
1529 "type": "bool",
1530 "desc": "try to parse invalid Swagger schemas",
1531 },
1532 "token": <ConnectionOptionInfo>{
1533 "type": "string",
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",
1538 "sensitive": True,
1539 },
1540 "token_type": <ConnectionOptionInfo>{
1541 "type": "string",
1542 "desc": "The type of `token` to use for the `Authentication` header; ignored if no `token` "
1543 "option is set",
1544 "default_value": "Bearer",
1545 },
1546 "username": <ConnectionOptionInfo>{
1547 "type": "string",
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",
1550 },
1551 "validator": <ConnectionOptionInfo>{
1552 "type": "any",
1553 "desc": "an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1554 "`swagger`",
1555 },
1556 },
1557 };
1558
1560 const Options = map {$1: True}, keys ConnectionScheme.options;
1561
1563 const OptionList = keys ConnectionScheme.options;
1564
1567
1568
1570 const OAuth2Options = ...;
1571
1572
1574
1577 const RCF_OAUTH2_AUTH_CODE = "oauth2-auth-code";
1578
1579protected:
1581 hash<string, bool> features = {
1582 CF_LOGGER: True,
1583 };
1584
1585public:
1586
1588
1601 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1602 ;
1603
1604
1606
1608 string getOAuth2OptionName(string opt);
1609
1610
1612
1616 object getPollImpl();
1617
1618
1620
1624 hash<auto> getOptions();
1625
1626
1628 string getType();
1629
1630
1632
1634 hash<auto> getOAuth2Options();
1635
1636
1638
1640 hash<auto> processOAuth2TokenResponse(hash<auto> resp);
1641
1642
1644
1651
1652
1654
1659
1660
1662
1668
1669
1671
1673 static hash<auto> processOptions(*hash<auto> opts);
1674
1676
1683 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
1684
1685
1687 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1688 is to return a full URL
1689
1690 @since %RestClient 2.0
1691 */
1692 string getAuthUrl(*bool allow_relative);
1693
1694
1696 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1697 is to return a full URL
1698
1699 @since %RestClient 2.0
1700 */
1701 string getTokenUrl(*bool allow_relative);
1702
1703
1705 /*
1706 @since %RestClient 2.0
1707 */
1708protected:
1709 static softstring getUriValue(auto v);
1710public:
1711
1712
1714protected:
1715 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1716public:
1717
1718
1720protected:
1722public:
1723
1724
1726
1734protected:
1735 RestClient getImpl(bool connect = True, *hash<auto> rtopts);
1736public:
1737
1738
1740
1742protected:
1744public:
1745
1746
1748
1750protected:
1751 *hash<string, bool> getFeaturesImpl();
1752public:
1753
1754
1756protected:
1758public:
1759
1760
1762protected:
1763 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
1764public:
1765
1766};
1767
1769
1772
1773public:
1775 const SPS_GET_SWAGGER = 'get-swagger';
1776
1778 const SPS_OAUTH2_GET_TOKEN = "oauth2-get-token";
1779
1781 const SPS_OAUTH2_REFRESH_TOKEN = "oauth2-refresh-token";
1782
1784 const SPS_REST_PING = "rest-ping";
1785
1787 const SPS_COMPLETE = "complete";
1788
1789protected:
1792
1794 hash<auto> real_opts;
1795
1797 AbstractPollOperation poller;
1798
1800 bool goal_reached = False;
1801
1803 string method;
1804
1806 string path;
1807
1809 *auto body;
1810
1812 *hash<auto> headers;
1813
1815 string state;
1816
1818 Mutex m();
1819
1822
1825
1826public:
1827
1830
1831
1833
1835 string getGoal();
1836
1837
1839
1841 string getState();
1842
1843
1845
1848
1849
1851 *hash<SocketPollInfo> continuePoll();
1852
1853
1854protected:
1855 checkOtherStates();
1856public:
1857
1858
1859protected:
1860 gotOAuth2LoginInfo(hash<auto> h);
1861public:
1862
1863
1864protected:
1865 doStartGetToken();
1866public:
1867
1868
1869protected:
1870 doStartRefresh();
1871public:
1872
1873
1874protected:
1875 doStartPing();
1876public:
1877
1878};
1879};
*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.
string type(auto arg)
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