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;
578 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
622 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
666 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
721 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
776 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
788 private nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
789 string ct =
"Content-Type") {
791 hdr = {} + headers + hdr;
794 if (!path.val() && (*
string p = getConnectionPath()))
797 hash<RestRequestClientInfo> req = validator.
processRequest(method, path, body, hdr, sct);
870 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True,
872 prepareMsg(m, path, \body, \hdr);
874 on_exit
if (exists body);
880 on_error rethrow $1.err, sprintf(
"%s (REST URL %y)", $1.desc, getSafeURL());
882 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
889 softbool decode_errors = True, *hash<auto> hdr) {
891 hdr = {} + headers + hdr;
893 on_exit
if (exists body);
896 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
901 *reference<hash<auto>> info, *softbool decode_errors) {
904 h = send(body, m, path, hdr, False, \info);
905 info.
"response-code" = h.status_code;
906 }
catch (hash<ExceptionInfo> ex) {
907 info.
"response-code" = info.
"response-headers".status_code;
909 if (decode_errors && ex.arg.body) {
910 decodeError(ex.arg, \info);
911 ex.arg.deserialized_body = info.
"response-body";
915 rethrow ex.err, ex.desc, ex.arg;
919 if (exists h.body && !exists info.
"response-body") {
920 info.
"response-body" = h.body;
924 return processRestResponse(h, m, path, \info);
1003 "cls": Class::forName(
"RestConnection"),
1004 "options": HttpConnection::ConnectionScheme.options + {
1005 "content_encoding": <ConnectionOptionInfo>{
1007 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1008 "response encoding to request",
1012 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1013 }, <AllowedValueInfo>{
1015 "desc":
"use bzip2 encoding",
1016 }, <AllowedValueInfo>{
1018 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1019 }, <AllowedValueInfo>{
1020 "value":
"identity",
1021 "desc":
"use no content encoding",
1025 "data": <ConnectionOptionInfo>{
1027 "desc":
"data serialization options",
1031 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1032 }, <AllowedValueInfo>{
1034 "desc":
"for binary message bodies without data serialization",
1035 }, <AllowedValueInfo>{
1037 "desc":
"use JSON serialization",
1038 }, <AllowedValueInfo>{
1040 "desc":
"use raw XML serialization",
1041 }, <AllowedValueInfo>{
1043 "desc":
"use only plain text; no serialization is used",
1044 }, <AllowedValueInfo>{
1046 "desc":
"for URL-encoded message bodies",
1047 }, <AllowedValueInfo>{
1049 "desc":
"use only XML-RPC serialization",
1050 }, <AllowedValueInfo>{
1052 "desc":
"use only YAML serialization",
1055 "default_value":
"auto",
1057 "headers": <ConnectionOptionInfo>{
1059 "desc":
"an optional hash of headers to send with every request, these can also be "
1060 "overridden in request method calls",
1062 "ping_method": <ConnectionOptionInfo>{
1064 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make an "
1065 "HTTP request as a part of the socket polling ping operation; must be a valid HTTP method name",
1067 "ping_path": <ConnectionOptionInfo>{
1069 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make an "
1070 "HTTP request as a part of the socket polling ping operation",
1072 "ping_headers": <ConnectionOptionInfo>{
1074 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1075 "one of `ping_method` and `ping_path` are not set",
1077 "ping_body": <ConnectionOptionInfo>{
1079 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1080 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1082 "send_encoding": <ConnectionOptionInfo>{
1084 "desc":
"this sets the send encoding",
1088 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1089 }, <AllowedValueInfo>{
1091 "desc":
"use bzip2 encoding",
1092 }, <AllowedValueInfo>{
1094 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1095 }, <AllowedValueInfo>{
1096 "value":
"identity",
1097 "desc":
"use no content encoding",
1101 "swagger": <ConnectionOptionInfo>{
1102 "type":
"file-as-string",
1103 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1104 "`FileLocationHandler::getTextFileFromLocation()` "
1105 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1108 "swagger_base_path": <ConnectionOptionInfo>{
1110 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1111 "with this option (applies to any REST validator; not just Swagger validators)",
1113 "validator": <ConnectionOptionInfo>{
1115 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1145 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
static tryDecodeErrorResponse(reference< hash< auto > > h, *reference< hash< auto > > info)
tries to decode an error response
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:266
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 > 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:888
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...
static decodeError(hash< auto > h, *reference< hash< auto > > info)
decode any REST errors returned if possible
hash< auto > processRestResponse(hash< auto > resp, string method, string path, *reference< hash< auto > > info)
Process the raw REST response received.
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:870
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:788
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:263
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:900
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:995
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:1129
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:999
const Options
object connection options
Definition: RestClient.qm.dox.h:1122
const DefaultOptions
default options
Definition: RestClient.qm.dox.h:1125
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:1002
string getType()
returns "rest"
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling class.
Definition: RestClient.qm.dox.h:1270
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:1275
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1278
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