218 const DataSerializationSupport = {
220 "json": MimeTypeJson,
223 "yaml": MimeTypeYaml,
227 "rawxml": MimeTypeXmlApp,
229 "url": MimeTypeFormUrlEncoded,
230 "text": MimeTypeText,
231 "bin": MimeTypeOctetStream,
234 const DeserializeYaml = {
238 const DeserializeXml = {
241 "in": hash<auto> sub (
string xml, reference<string> type) {
243 on_success type =
"xml";
244 return parse_xmlrpc_value(xml);
245 }
catch (hash<ExceptionInfo> ex) {
247 on_success
type =
"rawxml";
248 return parse_xml(xml);
257 const AcceptList = ...;
261 const Accept = AcceptList.join(
",");
264 const AcceptMap = map {$1: True}, AcceptList;
267 const Version =
"1.7";
273 const DefaultHeaders = {
289 const DataSerializationOptions = {
313 const EncodingSupport = {
332 const CompressionThreshold = 1024;
582 hash<auto>
get(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
626 hash<auto>
put(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
670 hash<auto>
patch(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
725 hash<auto>
post(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
780 hash<auto>
del(
string path,
auto body, *reference<hash<auto>> info, *hash<auto> hdr);
792 private nothing
prepareMsg(
string method,
string path, reference<auto> body, reference<hash<auto>> hdr,
793 string ct =
"Content-Type") {
795 hdr = {} + headers + hdr;
798 if (!path.val() && (*
string p = getConnectionPath()))
801 hash<RestRequestClientInfo> req = validator.
processRequest(method, path, body, hdr, sct);
874 hash<auto>
doRequest(
string m,
string path,
auto body, *reference<hash<auto>> info, softbool decode_errors = True,
876 prepareMsg(m, path, \body, \hdr);
878 on_exit
if (exists body);
884 on_error rethrow $1.err, sprintf(
"%s (REST URL %y)", $1.desc, getSafeURL());
886 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
893 softbool decode_errors = True, *hash<auto> hdr) {
895 hdr = {} + headers + hdr;
897 on_exit
if (exists body);
900 return sendAndDecodeResponse(body, m, path, hdr, \info, decode_errors);
905 *reference<hash<auto>> info, *softbool decode_errors) {
908 h = send(body, m, path, hdr, False, \info);
909 info.
"response-code" = h.status_code;
910 }
catch (hash<ExceptionInfo> ex) {
911 info.
"response-code" = info.
"response-headers".status_code;
913 if (decode_errors && ex.arg.body) {
914 decodeError(ex.arg, \info);
915 ex.arg.deserialized_body = info.
"response-body";
919 rethrow ex.err, ex.desc, ex.arg;
923 if (exists h.body && !exists info.
"response-body") {
924 info.
"response-body" = h.body;
928 return processRestResponse(h, m, path, \info);
1008 "cls": Class::forName(
"RestConnection"),
1009 "options": HttpConnection::ConnectionScheme.options + {
1010 "content_encoding": <ConnectionOptionInfo>{
1012 "desc":
"this sets the send encoding (if the `send_encoding` option is not set) and the "
1013 "response encoding to request",
1017 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1018 }, <AllowedValueInfo>{
1020 "desc":
"use bzip2 encoding",
1021 }, <AllowedValueInfo>{
1023 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1024 }, <AllowedValueInfo>{
1025 "value":
"identity",
1026 "desc":
"use no content encoding",
1030 "data": <ConnectionOptionInfo>{
1032 "desc":
"data serialization options",
1036 "desc":
"prefers in this order: `json`, `yaml`, `rawxml`, `xml`, `url`, and `text`",
1037 }, <AllowedValueInfo>{
1039 "desc":
"for binary message bodies without data serialization",
1040 }, <AllowedValueInfo>{
1042 "desc":
"use JSON serialization",
1043 }, <AllowedValueInfo>{
1045 "desc":
"use raw XML serialization",
1046 }, <AllowedValueInfo>{
1048 "desc":
"use only plain text; no serialization is used",
1049 }, <AllowedValueInfo>{
1051 "desc":
"for URL-encoded message bodies",
1052 }, <AllowedValueInfo>{
1054 "desc":
"use only XML-RPC serialization",
1055 }, <AllowedValueInfo>{
1057 "desc":
"use only YAML serialization",
1060 "default_value":
"auto",
1062 "headers": <ConnectionOptionInfo>{
1064 "desc":
"an optional hash of headers to send with every request, these can also be "
1065 "overridden in request method calls",
1067 "ping_method": <ConnectionOptionInfo>{
1069 "desc":
"The HTTP method to use for an advanced ping; this and `ping_path` must be set to make an "
1070 "HTTP request as a part of the socket polling ping operation; must be a valid HTTP method name",
1072 "ping_path": <ConnectionOptionInfo>{
1074 "desc":
"The URI path to use for an advanced ping; this and `ping_method` must be made to make an "
1075 "HTTP request as a part of the socket polling ping operation",
1077 "ping_headers": <ConnectionOptionInfo>{
1079 "desc":
"Any HTTP headers to send when performing an advanced ping operation; ignored if either "
1080 "one of `ping_method` and `ping_path` are not set",
1082 "ping_body": <ConnectionOptionInfo>{
1084 "desc":
"Any message body to send when performing an advanced ping operation; ignored if either "
1085 "one of `ping_method` and `ping_path` are not set or if `ping_method` is `GET`",
1087 "send_encoding": <ConnectionOptionInfo>{
1089 "desc":
"this sets the send encoding",
1093 "desc":
"use GNU zip encoding ([RFC 1952](https://tools.ietf.org/html/rfc1952))",
1094 }, <AllowedValueInfo>{
1096 "desc":
"use bzip2 encoding",
1097 }, <AllowedValueInfo>{
1099 "desc":
"use the deflate algorithm ([RFC 1951](https://tools.ietf.org/html/rfc1951))",
1100 }, <AllowedValueInfo>{
1101 "value":
"identity",
1102 "desc":
"use no content encoding",
1106 "swagger": <ConnectionOptionInfo>{
1107 "type":
"file-as-string",
1108 "desc":
"the location of a Swagger schema to use for message validation; processed with "
1109 "`FileLocationHandler::getTextFileFromLocation()` "
1110 "(ex: `file:///path/to/swagger-schema.json`); conflicts with `validator`",
1113 "swagger_base_path": <ConnectionOptionInfo>{
1115 "desc":
"in case a REST validator is used, the base path in the schema can be overridden "
1116 "with this option (applies to any REST validator; not just Swagger validators)",
1118 "swagger_lax_parsing": <ConnectionOptionInfo>{
1120 "desc":
"try to parse invalid Swagger schemas",
1122 "validator": <ConnectionOptionInfo>{
1124 "desc":
"an `AbstractRestSchemaValidator` object for REST message validation; conflicts with "
1150 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:270
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:892
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:874
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:792
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:267
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:904
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:1000
bool hasDataProvider()
returns True, as this connection always returns a data provider with the getDataProvider() method
pingImpl()
performs the internal ping
const OptionList
object connection option list
Definition: RestClient.qm.dox.h:1134
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:1004
const Options
object connection options
Definition: RestClient.qm.dox.h:1131
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:1007
string getType()
returns "rest"
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
REST ping polling class.
Definition: RestClient.qm.dox.h:1272
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:1277
bool goal_reached
Goal reached flag.
Definition: RestClient.qm.dox.h:1280
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:212