Qore RestClient Module Reference 2.1.1
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
247namespace RestClient {
249
251public hashdecl AuthCodeInfo {
253 string response_type = "code";
254
257
259 *list<string> scopes;
260
262 *string state;
263};
264
266class RestClient : public Qore::HTTPClient, public Logger::LoggerWrapper, public ConnectionProvider::UpdateOptionsInterface {
267
268public:
270 const DataSerializationSupport = {
271%ifndef NoJson
272 "json": MimeTypeJson,
273%endif
274%ifndef NoYaml
275 "yaml": MimeTypeYaml,
276%endif
277%ifndef NoXml
278 "xml": MimeTypeXml,
279 "rawxml": MimeTypeXmlApp,
280%endif
281 "url": MimeTypeFormUrlEncoded,
282 "text": MimeTypeText,
283 "bin": MimeTypeOctetStream,
284 };
285
286 const DeserializeYaml = {
287 "code": "yaml",
288 "in": \parse_yaml(),
289 };
290 const DeserializeXml = {
291 "code": "xml",
292 "arg": True,
293 "in": hash<auto> sub (string xml, reference<string> type) {
294 try {
295 on_success type = "xml";
296 return parse_xmlrpc_value(xml);
297 } catch (hash<ExceptionInfo> ex) {
298 try {
299 on_success type = "rawxml";
300 return parse_xml(xml);
301 } catch () {
302 rethrow;
303 }
304 }
305 },
306 };
307
309 const AcceptList = ...;
310
311
313 const Accept = AcceptList.join(",");
314
316 const AcceptMap = map {$1: True}, AcceptList;
317
319 const Version = "2.0";
320
322 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
323
325 const DefaultHeaders = {
326 "Accept": Accept,
327 "User-Agent": RestClient::VersionString,
328 };
329
331 const DefaultOAuth2RedirectUrl = "auto";
332
334 const DefaultOptions = {
335 "oauth2_redirect_url": DefaultOAuth2RedirectUrl,
336 };
337
339
349 const DataSerializationOptions = {
350 "auto": True,
351%ifndef NoJson
352 "json": True,
353%endif
354%ifndef NoYaml
355 "yaml": True,
356%endif
357%ifndef NoXml
358 "rawxml": True,
359 "xml": True,
360%endif
361 "url": True,
362 "text": True,
363 "bin": True,
364 };
365
367
373 const EncodingSupport = {
374 "gzip": {
375 "ce": "gzip",
376 "func": \gzip(),
377 },
378 "bzip2": {
379 "ce": "bzip2",
380 "func": \bzip2(),
381 },
382 "deflate": {
383 "ce": "deflate",
384 "func": \compress(),
385 },
386 "identity": {
387 "ce": NOTHING,
388 },
389 };
390
392 const CompressionThreshold = 1024;
393
395
397 const OAuth2GrantOptions = {
398 "authorization_code": (
399 "oauth2_auth_url",
400 "oauth2_client_id",
401 "oauth2_client_secret",
402 "oauth2_redirect_url",
403 "oauth2_token_url",
404 ),
405 "client_credentials": (
406 "oauth2_client_id",
407 "oauth2_client_secret",
408 "oauth2_token_url",
409 ),
410 "password": (
411 "oauth2_client_id",
412 "oauth2_client_secret",
413 "oauth2_token_url",
414 ),
415 };
416
418 const OAuth2AuthHeaders = {
419 // this will ensure that OAuth2 servers do not prefer XML or other serialization with a different data
420 # format (ex: the Salesforce OAuth2 server)
421 "Accept": MimeTypeFormUrlEncoded + "," + MimeTypeJson,
422 };
423
425 const MinimumTokenRefresh = 1m;
426
427protected:
428 // headers to send with every request
429 hash<auto> headers;
430 // data serialization code
431 string ds;
432 // serialization content type
433 string sct;
434 // send content encoding hash
435 *hash<auto> seh;
436 // REST schema validator
438 // no_charset option
439 *bool noCharset;
440
442 string username;
444 string password;
445
453 *softlist<string> oauth2_scopes;
455 *hash<auto> oauth2_auth_args;
465 string token;
469 bool oauth2_auto_refresh = True;
472
473public:
474
476
574 constructor(*hash<auto> opts, *softbool do_not_connect) ;
575
576
578
581
582
584
597 setSerialization(string data = 'auto');
598
599
601
618 setSendEncoding(string enc = 'auto');
619
620
622
639 setContentEncoding(string enc = 'auto');
640
641
643
659 addDefaultHeaders(hash<auto> h);
660
661
663
676 hash<auto> getDefaultHeaders();
677
678
680
685 replaceDefaultHeaders(*hash<auto> hdr);
686
687
689
705
706
708
721
722
724
778 hash<auto> get(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
779
780
782
833 hash<auto> put(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
834
835
837
888 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
889
890
892
943 hash<auto> post(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
944
945
947
998 hash<auto> del(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
999
1000
1002
1007
1008
1010
1013
1014
1016
1019
1020
1022
1025
1026
1028
1030 setToken(string token_type, string token, *string refresh_token);
1031
1032
1034
1037
1038
1040
1042 *string getToken();
1043
1044
1046
1048 AbstractPollOperation startOAuth2PollSendRecv();
1049
1050
1052
1054 AbstractPollOperation startOAuth2PollRefreshToken();
1055
1056
1058
1103 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1104
1105
1107protected:
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);
1109public:
1110
1111
1113
1120 prepareToSend(string method, reference<string> path, reference<auto> body, *reference<hash<auto>> hdr);
1121
1122
1124
1126 hash<auto> doValidatedRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
1127
1128
1130
1137 hash<auto> processRestResponse(hash<auto> resp, string method, string path, *reference<hash<auto>> info);
1138
1139
1141
1143 hash<auto> gotOAuth2LoginInfo(hash<auto> h);
1144
1145
1147
1149protected:
1150 setOAuth2LoginInfo(hash<auto> h);
1151public:
1152
1153
1155
1157protected:
1158 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h);
1159public:
1160
1161
1163
1165protected:
1166 setupAuth(hash<auto> opts);
1167public:
1168
1169
1171
1173protected:
1174 checkOAuth2Options(hash<auto> opts);
1175public:
1176
1177
1179
1181protected:
1182 hash<auto> loginIntern(*reference<hash<auto>> info);
1183public:
1184
1185
1187
1189protected:
1190 AbstractPollOperation startOAuth2AuthPoll(hash<auto> login);
1191public:
1192
1193
1195
1197protected:
1198 hash<auto> oauth2Auth(hash<auto> login, *reference<hash<auto>> info);
1199public:
1200
1201
1203
1205protected:
1206 hash<auto> doOAuth2LoginRequest(string url, hash<auto> login, *reference<hash<auto>> info);
1207public:
1208
1209
1211
1213protected:
1215public:
1216
1217
1219
1221protected:
1222 hash<auto> getOAuth2LoginInfo(string grant_type);
1223public:
1224
1225
1227
1229protected:
1231public:
1232
1233
1235protected:
1236 nothing prepareMsg(string method, string path, reference<auto> body, reference<hash<auto>> hdr, string ct = 'Content-Type');
1237public:
1238
1239
1241protected:
1242 nothing preparePath(reference<string> path);
1243public:
1244
1245
1247protected:
1248 checkLogin(*reference<hash<auto>> info);
1249public:
1250
1251
1253protected:
1254 hash<auto> sendAndDecodeResponse(*data body, string m, string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors, *string assume_content_type);
1255public:
1256
1257
1259protected:
1260 static decodeError(hash<auto> h, *reference<hash<auto>> info);
1261public:
1262
1263
1265private:
1266 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1267public:
1268
1269
1270}; // class RestClient
1271
1273
1346
1347public:
1349 hash<auto> real_opts;
1350
1352 const ConnectionScheme = <ConnectionSchemeInfo>{
1353 "cls": Class::forName("RestConnection"),
1354 "options": HttpConnection::ConnectionScheme.options + {
1355 "content_encoding": <ConnectionOptionInfo>{
1356 "type": "string",
1357 "desc": "this sets the send encoding (if the `send_encoding` option is not set) and the "
1358 "response encoding to request",
1359 "allowed_values": (
1360 <AllowedValueInfo>{
1361 "value": "gzip",
1362 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1363 }, <AllowedValueInfo>{
1364 "value": "bzip2",
1365 "desc": "use bzip2 encoding",
1366 }, <AllowedValueInfo>{
1367 "value": "deflate",
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",
1372 },
1373 ),
1374 },
1375 "data": <ConnectionOptionInfo>{
1376 "type": "string",
1377 "desc": "data serialization options",
1378 "allowed_values": (
1379 <AllowedValueInfo>{
1380 "value": "auto",
1381 "desc": "prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1382 }, <AllowedValueInfo>{
1383 "value": "bin",
1384 "desc": "for binary message bodies without data serialization",
1385 }, <AllowedValueInfo>{
1386 "value": "json",
1387 "desc": "use JSON serialization",
1388 }, <AllowedValueInfo>{
1389 "value": "rawxml",
1390 "desc": "use raw XML serialization",
1391 }, <AllowedValueInfo>{
1392 "value": "text",
1393 "desc": "use only plain text; no serialization is used",
1394 }, <AllowedValueInfo>{
1395 "value": "url",
1396 "desc": "for URL-encoded message bodies",
1397 }, <AllowedValueInfo>{
1398 "value": "xml",
1399 "desc": "use only XML-RPC serialization",
1400 }, <AllowedValueInfo>{
1401 "value": "yaml",
1402 "desc": "use only YAML serialization",
1403 },
1404 ),
1405 "default_value": "auto",
1406 },
1407 "headers": <ConnectionOptionInfo>{
1408 "type": "hash",
1409 "desc": "an optional hash of headers to send with every request, these can also be "
1410 "overridden in request method calls",
1411 },
1412 "oauth2_auth_args": <ConnectionOptionInfo>{
1413 "type": "hash",
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",
1417 },
1418 "oauth2_auth_url": <ConnectionOptionInfo>{
1419 "type": "string",
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",
1423 },
1424 "oauth2_auto_refresh": <ConnectionOptionInfo>{
1425 "type": "bool",
1426 "desc": "If OAuth2 tokens should be automatically refreshed",
1427 "default_value": True,
1428 },
1429 "oauth2_client_id": <ConnectionOptionInfo>{
1430 "type": "string",
1431 "desc": "The OAuth2 client ID; ignored if the `token` option is set",
1432 },
1433 "oauth2_client_secret": <ConnectionOptionInfo>{
1434 "type": "string",
1435 "desc": "the OAuth2 client secret; ignored if the `token` option is set",
1436 "sensitive": True,
1437 },
1438 "oauth2_grant_type": <ConnectionOptionInfo>{
1439 "type": "string",
1440 "desc": "The OAuth2 grant type; ignored if the `token` option is set",
1441 "allowed_values": (
1442 <AllowedValueInfo>{
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))",
1460 },
1461 ),
1462 },
1463 "oauth2_redirect_url": <ConnectionOptionInfo>{
1464 "type": "string",
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 "
1469 "client handling",
1470 "default_value": "auto",
1471 },
1472 "oauth2_refresh_token": <ConnectionOptionInfo>{
1473 "type": "string",
1474 "desc": "the OAuth2 refresh token, if any (complements option `token`)",
1475 "sensitive": True,
1476 },
1477 "oauth2_scopes": <ConnectionOptionInfo>{
1478 "type": "list",
1479 "desc": "Space-separated string of OAuth2 scopes to request; ignored if the `token` option is set",
1480 },
1481 "oauth2_token_url": <ConnectionOptionInfo>{
1482 "type": "string",
1483 "desc": "The token URL for OAuth2 flows; ignored if the `token` option is set",
1484 },
1485 "password": <ConnectionOptionInfo>{
1486 "type": "string",
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",
1489 "sensitive": True,
1490 },
1491 "ping_method": <ConnectionOptionInfo>{
1492 "type": "string",
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 "
1495 "name",
1496 },
1497 "ping_path": <ConnectionOptionInfo>{
1498 "type": "string",
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.",
1503 },
1504 "ping_headers": <ConnectionOptionInfo>{
1505 "type": "hash",
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",
1508 },
1509 "ping_body": <ConnectionOptionInfo>{
1510 "type": "any",
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`",
1513 },
1514 "send_encoding": <ConnectionOptionInfo>{
1515 "type": "string",
1516 "desc": "this sets the send encoding",
1517 "allowed_values": (
1518 <AllowedValueInfo>{
1519 "value": "gzip",
1520 "desc": "use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1521 }, <AllowedValueInfo>{
1522 "value": "bzip2",
1523 "desc": "use bzip2 encoding",
1524 }, <AllowedValueInfo>{
1525 "value": "deflate",
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",
1530 },
1531 ),
1532 },
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`",
1538 "freeform": True,
1539 },
1540 "swagger_base_path": <ConnectionOptionInfo>{
1541 "type": "string",
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)",
1544 },
1545 "swagger_lax_parsing": <ConnectionOptionInfo>{
1546 "type": "bool",
1547 "desc": "try to parse invalid Swagger schemas",
1548 },
1549 "token": <ConnectionOptionInfo>{
1550 "type": "string",
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",
1555 "sensitive": True,
1556 },
1557 "token_type": <ConnectionOptionInfo>{
1558 "type": "string",
1559 "desc": "The type of `token` to use for the `Authentication` header; ignored if no `token` "
1560 "option is set",
1561 "default_value": "Bearer",
1562 },
1563 "username": <ConnectionOptionInfo>{
1564 "type": "string",
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",
1567 },
1568 "validator": <ConnectionOptionInfo>{
1569 "type": "any",
1570 "desc": "an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1571 "`swagger`",
1572 },
1573 },
1574 };
1575
1577 const Options = map {$1: True}, keys ConnectionScheme.options;
1578
1580 const OptionList = keys ConnectionScheme.options;
1581
1584
1585
1587 const OAuth2Options = ...;
1588
1589
1591
1594 const RCF_OAUTH2_AUTH_CODE = "oauth2-auth-code";
1595
1596protected:
1598 hash<string, bool> features = {
1599 CF_LOGGER: True,
1600 };
1601
1602public:
1603
1605
1618 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1619 ;
1620
1621
1623
1625 string getOAuth2OptionName(string opt);
1626
1627
1629
1633 object getPollImpl();
1634
1635
1637
1641 hash<auto> getOptions();
1642
1643
1645 string getType();
1646
1647
1649
1651 hash<auto> getOAuth2Options();
1652
1653
1655
1657 hash<auto> processOAuth2TokenResponse(hash<auto> resp);
1658
1659
1661
1668
1669
1671
1676
1677
1679
1685
1686
1688
1690 static hash<auto> processOptions(*hash<auto> opts);
1691
1693
1700 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
1701
1702
1704 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1705 is to return a full URL
1706
1707 @since %RestClient 2.0
1708 */
1709 string getAuthUrl(*bool allow_relative);
1710
1711
1713 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1714 is to return a full URL
1715
1716 @since %RestClient 2.0
1717 */
1718 string getTokenUrl(*bool allow_relative);
1719
1720
1722 /* @param opt the URL option name
1723 @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
1724 is to return a full URL
1725
1726 @since %RestClient 2.1.1
1727 */
1728protected:
1729 string getUrlOption(string opt, *bool allow_relative);
1730public:
1731
1732
1734 /*
1735 @since %RestClient 2.0
1736 */
1737protected:
1738 static softstring getUriValue(auto v);
1739public:
1740
1741
1743protected:
1744 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1745public:
1746
1747
1749protected:
1751public:
1752
1753
1755
1763protected:
1764 RestClient getImpl(bool connect = True, *hash<auto> rtopts);
1765public:
1766
1767
1769
1771protected:
1773public:
1774
1775
1777
1779protected:
1780 *hash<string, bool> getFeaturesImpl();
1781public:
1782
1783
1785protected:
1787public:
1788
1789
1791protected:
1792 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
1793public:
1794
1795};
1796
1798
1801
1802public:
1804 const SPS_GET_SWAGGER = 'get-swagger';
1805
1807 const SPS_OAUTH2_GET_TOKEN = "oauth2-get-token";
1808
1810 const SPS_OAUTH2_REFRESH_TOKEN = "oauth2-refresh-token";
1811
1813 const SPS_REST_PING = "rest-ping";
1814
1816 const SPS_COMPLETE = "complete";
1817
1818protected:
1821
1823 hash<auto> real_opts;
1824
1826 AbstractPollOperation poller;
1827
1829 bool goal_reached = False;
1830
1832 string method;
1833
1835 string path;
1836
1838 *auto body;
1839
1841 *hash<auto> headers;
1842
1844 string state;
1845
1847 Mutex m();
1848
1851
1854
1855public:
1856
1859
1860
1862
1864 string getGoal();
1865
1866
1868
1870 string getState();
1871
1872
1874
1877
1878
1880 *hash<SocketPollInfo> continuePoll();
1881
1882
1883protected:
1884 checkOtherStates();
1885public:
1886
1887
1888protected:
1889 gotOAuth2LoginInfo(hash<auto> h);
1890public:
1891
1892
1893protected:
1894 doStartGetToken();
1895public:
1896
1897
1898protected:
1899 doStartRefresh();
1900public:
1901
1902
1903protected:
1904 doStartPing();
1905public:
1906
1907};
1908};
*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.
string type(auto arg)
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