210 const DataSerializationSupport = {
212 "json": MimeTypeJson,
215 "yaml": MimeTypeYaml,
219 "rawxml": MimeTypeXmlApp,
221 "url": MimeTypeFormUrlEncoded,
222 "text": MimeTypeText,
223 "bin": MimeTypeOctetStream,
226 const DeserializeYaml = {
230 const DeserializeXml = {
233 "in": hash<auto> sub (
string xml, reference<string> type) {
235 on_success type =
"xml";
236 return parse_xmlrpc_value(xml);
237 }
catch (hash<ExceptionInfo> ex) {
239 on_success
type =
"rawxml";
240 return parse_xml(xml);
249 const AcceptList = ...;
253 const Accept = AcceptList.join(
",");
256 const AcceptMap = map {$1: True}, AcceptList;
259 const Version =
"1.7";
265 const DefaultHeaders = {
281 const DataSerializationOptions = {
305 const EncodingSupport = {
324 const CompressionThreshold = 1024;
404 constructor(*hash<auto> opts, *softbool do_not_connect) : HTTPClient(opts + ((opts.url || !opts.validator)
412 clearConnectionPath();
427 setSerialization(
string data =
'auto');
446 setSendEncoding(
string enc =
'auto');
465 setContentEncoding(
string enc =
'auto');
483 addDefaultHeaders(hash<auto> h);
500 hash<auto> getDefaultHeaders();
517 *
string getSendEncoding();
530 string getSerialization();
575 hash<auto> get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
619 hash<auto> put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
663 hash<auto> patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
718 hash<auto> post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
773 hash<auto> del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
785 private nothing prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
786 string ct =
"Content-Type") {
788 hdr = {} + headers + hdr;
791 if (!path.val() && (*
string p = getConnectionPath()))
794 hash<RestRequestClientInfo> req = validator.
processRequest(method, path, body, hdr, sct);
802 nothing preparePath(reference<string> path);
867 hash<auto> doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True,
869 prepareMsg(m, path, \body, \hdr);
871 on_exit
if (exists body);
877 on_error rethrow $1.err, sprintf(
"%s (REST URL %y)", $1.desc, getSafeURL());
879 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
885 hash<auto> doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info,
886 softbool decode_errors = True, *hash<auto> hdr) {
888 hdr = {} + headers + hdr;
890 on_exit
if (exists body);
893 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
897 private hash<auto> sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr,
898 *reference<hash<auto>> info, *softbool decode_errors) {
901 h = send(body, m, path, hdr, False, \info);
902 info.
"response-code" = h.status_code;
903 }
catch (hash<ExceptionInfo> ex) {
904 info.
"response-code" = info.
"response-headers".status_code;
906 if (decode_errors && ex.arg.body) {
907 decodeError(ex.arg, \info);
908 ex.arg.deserialized_body = info.
"response-body";
912 rethrow ex.err, ex.desc, ex.arg;
916 if (exists h.body && !exists info.
"response-body") {
917 info.
"response-body" = h.body;
921 return processRestResponse(h, m, path, \info);
933 hash<auto> processRestResponse(hash<auto> resp,
string method,
string path, *reference<hash<auto>> info);
939 static decodeError(hash<auto> h, *reference<hash<auto>> info);
945 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1000 "cls": Class::forName(
"RestConnection"),
1001 "options": HttpConnection::ConnectionScheme.options + {
1002 "content_encoding": <ConnectionOptionInfo>{
1004 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1005 "response encoding to request",
1009 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1010 }, <AllowedValueInfo>{
1012 "desc":
"use bzip2 encoding",
1013 }, <AllowedValueInfo>{
1015 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1016 }, <AllowedValueInfo>{
1017 "value":
"identity",
1018 "desc":
"use no content encoding",
1022 "data": <ConnectionOptionInfo>{
1024 "desc":
"data serialization options",
1028 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1029 }, <AllowedValueInfo>{
1031 "desc":
"for binary message bodies without data serialization",
1032 }, <AllowedValueInfo>{
1034 "desc":
"use JSON serialization",
1035 }, <AllowedValueInfo>{
1037 "desc":
"use raw XML serialization",
1038 }, <AllowedValueInfo>{
1040 "desc":
"use only plain text; no serialization is used",
1041 }, <AllowedValueInfo>{
1043 "desc":
"for URL-encoded message bodies",
1044 }, <AllowedValueInfo>{
1046 "desc":
"use only XML-RPC serialization",
1047 }, <AllowedValueInfo>{
1049 "desc":
"use only YAML serialization",
1052 "default_value":
"auto",
1054 "headers": <ConnectionOptionInfo>{
1056 "desc":
"an optional hash of headers to send with every request, these can also be "
1057 "overridden in request method calls",
1059 "ping_method": <ConnectionOptionInfo>{
1061 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make an "
1062 "HTTP request as a part of the socket polling ping operation; must be a valid HTTP method name",
1064 "ping_path": <ConnectionOptionInfo>{
1066 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make an "
1067 "HTTP request as a part of the socket polling ping operation",
1069 "ping_headers": <ConnectionOptionInfo>{
1071 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1072 "one of `ping_method` and `ping_path` are not set",
1074 "ping_body": <ConnectionOptionInfo>{
1076 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1077 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1079 "send_encoding": <ConnectionOptionInfo>{
1081 "desc":
"this sets the send encoding",
1085 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1086 }, <AllowedValueInfo>{
1088 "desc":
"use bzip2 encoding",
1089 }, <AllowedValueInfo>{
1091 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1092 }, <AllowedValueInfo>{
1093 "value":
"identity",
1094 "desc":
"use no content encoding",
1098 "swagger": <ConnectionOptionInfo>{
1100 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1101 "`FileLocationHandler::getTextFileFromLocation()` "
1102 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1104 "swagger_base_path": <ConnectionOptionInfo>{
1106 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1107 "with this option (applies to any REST validator; not just Swagger validators)",
1109 "validator": <ConnectionOptionInfo>{
1111 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1141 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:262
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:259
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:992
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
*hash< auto > getDefaultOptions()
returns default options
pingImpl()
performs the internal ping
const OptionList
object connection option list
Definition: RestClient.qm.dox.h:1125
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:996
const Options
object connection options
Definition: RestClient.qm.dox.h:1118
const DefaultOptions
default options
Definition: RestClient.qm.dox.h:1121
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
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.
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 ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:999
string getType()
returns "rest"
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling class.
Definition: RestClient.qm.dox.h:1266
constructor(AbstractPollOperation poller)
Creates the object with the send/receive poller.
*hash< SocketPollInfo > continuePoll()
Returns a hash to be used for I/O polling or NOTHING in case the poll operation is complete.
string getGoal()
Returns the goal.
bool goalReached()
Returns True when the goal as been reached.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1271
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1274
string getState()
Returns the current state.
Mutex m()
Lock for atomicity.
hash< RestRequestClientInfo > processRequest(string method, string path, auto body, *hash< auto > headers, *softlist< string > content_types)
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:204