222 const DataSerializationSupport = {
224 "json": MimeTypeJson,
227 "yaml": MimeTypeYaml,
231 "rawxml": MimeTypeXmlApp,
233 "url": MimeTypeFormUrlEncoded,
234 "text": MimeTypeText,
235 "bin": MimeTypeOctetStream,
238 const DeserializeYaml = {
242 const DeserializeXml = {
245 "in": hash<auto> sub (
string xml, reference<string> type) {
247 on_success type =
"xml";
248 return parse_xmlrpc_value(xml);
249 }
catch (hash<ExceptionInfo> ex) {
251 on_success
type =
"rawxml";
252 return parse_xml(xml);
261 const AcceptList = ...;
265 const Accept = AcceptList.join(
",");
268 const AcceptMap = map {$1: True}, AcceptList;
271 const Version =
"1.7";
277 const DefaultHeaders = {
293 const DataSerializationOptions = {
317 const EncodingSupport = {
336 const CompressionThreshold = 1024;
586 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
630 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
674 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
729 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
784 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
796 private nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
797 string ct =
"Content-Type") {
799 hdr = {} + headers + hdr;
802 if (!path.val() && (*
string p = getConnectionPath()))
805 hash<RestRequestClientInfo> req = validator.
processRequest(method, path, body, hdr, sct);
878 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True,
880 prepareMsg(m, path, \body, \hdr);
882 on_exit
if (exists body);
889 string url = getSafeURL();
895 rethrow $1.err, sprintf(
"%s (REST URL %y)", $1.desc, url);
904 hash<auto>
doValidatedRequest(
string m,
string path,
auto body, *reference<hash<auto>> info,
905 softbool decode_errors = True, *hash<auto> hdr) {
907 hdr = {} + headers + hdr;
909 on_exit
if (exists body);
917 *reference<hash<auto>> info, *softbool decode_errors) {
920 h = send(body, m, path, hdr, False, \info);
921 info.
"response-code" = h.status_code;
922 }
catch (hash<ExceptionInfo> ex) {
923 info.
"response-code" = info.
"response-headers".status_code;
925 if (decode_errors && ex.arg.body) {
926 decodeError(ex.arg, \info);
927 ex.arg.deserialized_body = info.
"response-body";
931 rethrow ex.err, ex.desc, ex.arg;
935 if (exists h.body && !exists info.
"response-body") {
936 info.
"response-body" = h.body;
958 static decodeError(hash<auto> h, *reference<hash<auto>> info);
964 static tryDecodeErrorResponse(reference<hash<auto>> h, *reference<hash<auto>> info);
1020 "cls": Class::forName(
"RestConnection"),
1021 "options": HttpConnection::ConnectionScheme.options + {
1022 "content_encoding": <ConnectionOptionInfo>{
1024 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1025 "response encoding to request",
1029 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1030 }, <AllowedValueInfo>{
1032 "desc":
"use bzip2 encoding",
1033 }, <AllowedValueInfo>{
1035 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1036 }, <AllowedValueInfo>{
1037 "value":
"identity",
1038 "desc":
"use no content encoding",
1042 "data": <ConnectionOptionInfo>{
1044 "desc":
"data serialization options",
1048 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1049 }, <AllowedValueInfo>{
1051 "desc":
"for binary message bodies without data serialization",
1052 }, <AllowedValueInfo>{
1054 "desc":
"use JSON serialization",
1055 }, <AllowedValueInfo>{
1057 "desc":
"use raw XML serialization",
1058 }, <AllowedValueInfo>{
1060 "desc":
"use only plain text; no serialization is used",
1061 }, <AllowedValueInfo>{
1063 "desc":
"for URL-encoded message bodies",
1064 }, <AllowedValueInfo>{
1066 "desc":
"use only XML-RPC serialization",
1067 }, <AllowedValueInfo>{
1069 "desc":
"use only YAML serialization",
1072 "default_value":
"auto",
1074 "headers": <ConnectionOptionInfo>{
1076 "desc":
"an optional hash of headers to send with every request, these can also be "
1077 "overridden in request method calls",
1079 "ping_method": <ConnectionOptionInfo>{
1081 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make an "
1082 "HTTP request as a part of the socket polling ping operation; must be a valid HTTP method name",
1084 "ping_path": <ConnectionOptionInfo>{
1086 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make an "
1087 "HTTP request as a part of the socket polling ping operation",
1089 "ping_headers": <ConnectionOptionInfo>{
1091 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1092 "one of `ping_method` and `ping_path` are not set",
1094 "ping_body": <ConnectionOptionInfo>{
1096 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1097 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1099 "send_encoding": <ConnectionOptionInfo>{
1101 "desc":
"this sets the send encoding",
1105 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1106 }, <AllowedValueInfo>{
1108 "desc":
"use bzip2 encoding",
1109 }, <AllowedValueInfo>{
1111 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1112 }, <AllowedValueInfo>{
1113 "value":
"identity",
1114 "desc":
"use no content encoding",
1118 "swagger": <ConnectionOptionInfo>{
1119 "type":
"file-as-string",
1120 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1121 "`FileLocationHandler::getTextFileFromLocation()` "
1122 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1125 "swagger_base_path": <ConnectionOptionInfo>{
1127 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1128 "with this option (applies to any REST validator; not just Swagger validators)",
1130 "swagger_lax_parsing": <ConnectionOptionInfo>{
1132 "desc":
"try to parse invalid Swagger schemas",
1134 "validator": <ConnectionOptionInfo>{
1136 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1162 constructor(
string name,
string description,
string url, hash<auto> attributes = {}, hash<auto> options = {})
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
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:274
constructor(*hash< auto > opts, *softbool do_not_connect)
calls the base class HTTPClient constructor and optionally connects to the REST server
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
setContentEncoding(string enc='auto')
sets the request and desired response encoding for the object; see EncodingSupport for valid options
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
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; see EncodingSupport for valid o...
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
Definition: RestClient.qm.dox.h:878
addDefaultHeaders(hash< auto > h)
adds default headers to each request; these headers will be sent in all requests but can be overridde...
private 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
Definition: RestClient.qm.dox.h:796
string getSerialization()
returns the current data serialization format currently in effect for the object (see DataSerializati...
*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:271
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:1012
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
RestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a RestClient object
hash< auto > real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:1016
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
Qore::AbstractPollOperation startPollConnect()
Called to start a non-blocking polling ping operation on the remote REST server.
const Options
object connection options
Definition: RestClient.qm.dox.h:1143
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
string getType()
returns "rest"
hash< auto > getOptions()
gets options
const ConnectionScheme
Connection entry info.
Definition: RestClient.qm.dox.h:1019
object getPollImpl()
Returns an unconnected object for a non-blocking poll operation.
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the RestConnection connection object
const OptionList
object connection option list
Definition: RestClient.qm.dox.h:1146
static hash< auto > processOptions(*hash< auto > opts)
processes options for the constructor
setChildCapabilities()
Sets child data provider capabilities.
pingImpl()
performs the internal ping
REST ping polling class.
Definition: RestClient.qm.dox.h:1284
constructor(AbstractPollOperation poller)
Creates the object with the send/receive poller.
AbstractPollOperation poller
The polling object.
Definition: RestClient.qm.dox.h:1289
Mutex m()
Lock for atomicity.
bool goalReached()
Returns True when the goal as been reached.
string getGoal()
Returns the goal.
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1292
*hash< SocketPollInfo > continuePoll()
Returns a hash to be used for I/O polling or NOTHING in case the poll operation is complete.
string getState()
Returns the current state.
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:216
hash< auto > processRestResponse(hash< auto > resp, string method, string path, *reference< hash< auto > > info)
Process the raw REST response received.
RestClient::RestClient Qore::HTTPClient 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.
Definition: RestClient.qm.dox.h:904
private hash< auto > sendAndDecodeResponse(*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors)
sends the outgoing HTTP message and recodes the response to data
Definition: RestClient.qm.dox.h:916