214 const DataSerializationSupport = {
216 "json": MimeTypeJson,
219 "yaml": MimeTypeYaml,
223 "rawxml": MimeTypeXmlApp,
225 "url": MimeTypeFormUrlEncoded,
226 "text": MimeTypeText,
227 "bin": MimeTypeOctetStream,
230 const DeserializeYaml = {
234 const DeserializeXml = {
237 "in": hash<auto> sub (
string xml, reference<string> type) {
239 on_success type =
"xml";
240 return parse_xmlrpc_value(xml);
241 }
catch (hash<ExceptionInfo> ex) {
243 on_success
type =
"rawxml";
244 return parse_xml(xml);
253 const AcceptList = ...;
257 const Accept = AcceptList.join(
",");
260 const AcceptMap = map {$1: True}, AcceptList;
263 const Version =
"1.7";
269 const DefaultHeaders = {
285 const DataSerializationOptions = {
309 const EncodingSupport = {
328 const CompressionThreshold = 1024;
408 constructor(*hash<auto> opts, *softbool do_not_connect) : HTTPClient(opts + ((opts.url || !opts.validator)
416 clearConnectionPath();
431 setSerialization(
string data =
'auto');
450 setSendEncoding(
string enc =
'auto');
469 setContentEncoding(
string enc =
'auto');
487 addDefaultHeaders(hash<auto> h);
504 hash<auto> getDefaultHeaders();
521 *
string getSendEncoding();
534 string getSerialization();
579 hash<auto> get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
623 hash<auto> put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
667 hash<auto> patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
722 hash<auto> post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
777 hash<auto> del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
789 private nothing prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
790 string ct =
"Content-Type") {
792 hdr = {} + headers + hdr;
795 if (!path.val() && (*
string p = getConnectionPath()))
798 hash<RestRequestClientInfo> req = validator.
processRequest(method, path, body, hdr, sct);
806 nothing preparePath(reference<string> path);
871 hash<auto> doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True,
873 prepareMsg(m, path, \body, \hdr);
875 on_exit
if (exists body);
881 on_error rethrow $1.err, sprintf(
"%s (REST URL %y)", $1.desc, getSafeURL());
883 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
889 hash<auto> doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info,
890 softbool decode_errors = True, *hash<auto> hdr) {
892 hdr = {} + headers + hdr;
894 on_exit
if (exists body);
897 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
901 private hash<auto> sendAndDecodeResponse(*data body,
string m,
string path, hash<auto> hdr,
902 *reference<hash<auto>> info, *softbool decode_errors) {
905 h = send(body, m, path, hdr, False, \info);
906 info.
"response-code" = h.status_code;
907 }
catch (hash<ExceptionInfo> ex) {
908 info.
"response-code" = info.
"response-headers".status_code;
910 if (decode_errors && ex.arg.body) {
911 decodeError(ex.arg, \info);
912 ex.arg.deserialized_body = info.
"response-body";
916 rethrow ex.err, ex.desc, ex.arg;
920 if (exists h.body && !exists info.
"response-body") {
921 info.
"response-body" = h.body;
925 return processRestResponse(h, m, path, \info);
937 hash<auto> processRestResponse(hash<auto> resp,
string method,
string path, *reference<hash<auto>> info);
943 static decodeError(hash<auto> h, *reference<hash<auto>> info);
949 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1004 "cls": Class::forName(
"RestConnection"),
1005 "options": HttpConnection::ConnectionScheme.options + {
1006 "content_encoding": <ConnectionOptionInfo>{
1008 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1009 "response encoding to request",
1013 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1014 }, <AllowedValueInfo>{
1016 "desc":
"use bzip2 encoding",
1017 }, <AllowedValueInfo>{
1019 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1020 }, <AllowedValueInfo>{
1021 "value":
"identity",
1022 "desc":
"use no content encoding",
1026 "data": <ConnectionOptionInfo>{
1028 "desc":
"data serialization options",
1032 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1033 }, <AllowedValueInfo>{
1035 "desc":
"for binary message bodies without data serialization",
1036 }, <AllowedValueInfo>{
1038 "desc":
"use JSON serialization",
1039 }, <AllowedValueInfo>{
1041 "desc":
"use raw XML serialization",
1042 }, <AllowedValueInfo>{
1044 "desc":
"use only plain text; no serialization is used",
1045 }, <AllowedValueInfo>{
1047 "desc":
"for URL-encoded message bodies",
1048 }, <AllowedValueInfo>{
1050 "desc":
"use only XML-RPC serialization",
1051 }, <AllowedValueInfo>{
1053 "desc":
"use only YAML serialization",
1056 "default_value":
"auto",
1058 "headers": <ConnectionOptionInfo>{
1060 "desc":
"an optional hash of headers to send with every request, these can also be "
1061 "overridden in request method calls",
1063 "ping_method": <ConnectionOptionInfo>{
1065 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make an "
1066 "HTTP request as a part of the socket polling ping operation; must be a valid HTTP method name",
1068 "ping_path": <ConnectionOptionInfo>{
1070 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make an "
1071 "HTTP request as a part of the socket polling ping operation",
1073 "ping_headers": <ConnectionOptionInfo>{
1075 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1076 "one of `ping_method` and `ping_path` are not set",
1078 "ping_body": <ConnectionOptionInfo>{
1080 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1081 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1083 "send_encoding": <ConnectionOptionInfo>{
1085 "desc":
"this sets the send encoding",
1089 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1090 }, <AllowedValueInfo>{
1092 "desc":
"use bzip2 encoding",
1093 }, <AllowedValueInfo>{
1095 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1096 }, <AllowedValueInfo>{
1097 "value":
"identity",
1098 "desc":
"use no content encoding",
1102 "swagger": <ConnectionOptionInfo>{
1103 "type":
"file-as-string",
1104 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1105 "`FileLocationHandler::getTextFileFromLocation()` "
1106 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1109 "swagger_base_path": <ConnectionOptionInfo>{
1111 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1112 "with this option (applies to any REST validator; not just Swagger validators)",
1114 "validator": <ConnectionOptionInfo>{
1116 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1146 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:266
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:263
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:996
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:1130
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:1000
const Options
object connection options
Definition: RestClient.qm.dox.h:1123
const DefaultOptions
default options
Definition: RestClient.qm.dox.h:1126
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:1003
string getType()
returns "rest"
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling class.
Definition: RestClient.qm.dox.h:1271
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:1276
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1279
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:208