All Classes Namespaces Functions Variables Groups Pages
RestClient.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
// @file RestClient.qm Qore user module for calling REST services
/* RestClient.qm Copyright (C) 2013 - 2016 Qore Technologies, sro
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// this module requires Qore 0.8.12 or better
// require type definitions everywhere
// enable all warnings
// don't use "$" for vars, members, and methods, assume local variable scope
}
/* Version History - see below in docs
*/
namespace RestClient {
class RestClient : public Qore::HTTPClient {
public:
public :
const DataSerializationSupport = {
"json": (
"ct": MimeTypeJson,
"out": \make_json(),
),
"yaml": (
"ct": MimeTypeYaml,
"out": \make_yaml(),
),
"xml": (
"ct": MimeTypeXml,
"out": \make_xmlrpc_value(),
),
};
const DeserializeYaml = (
"code": "yaml",
"in": \parse_yaml(),
);
const DeserializeXmlRpc = (
"code": "xml",
"in": \parse_xmlrpc_value(),
);
const DataDeserializationSupport = {
MimeTypeJson: (
"code": "json",
"in": \parse_json(),
),
MimeTypeYamlRpc: DeserializeYaml,
MimeTypeYaml: DeserializeYaml,
MimeTypeXml: DeserializeXmlRpc,
MimeTypeXmlApp: DeserializeXmlRpc,
};
const AcceptList = (
MimeTypeYaml, MimeTypeYamlRpc,
MimeTypeXml, MimeTypeXmlApp,
MimeTypeJsonRpc,
);
const Accept = AcceptList.join(",");
const Version = "1.3";
const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
const DefaultHeaders = (
"Accept": Accept,
"User-Agent": RestClient::VersionString,
);
const DataSerializationOptions = (
"auto": True,
"xml": True,
"json": True,
"yaml": True,
);
const EncodingSupport = (
"gzip": (
"ce": "gzip",
"func": \gzip(),
),
"bzip2": (
"ce": "bzip2",
"func": \bzip2(),
),
"deflate": (
"ce": "deflate",
"func": \compress(),
),
"identity": (
"ce": NOTHING,
),
);
const CompressionThreshold = 1024;
public:
private :
// headers to send with every request
hash headers;
// data serialization code
string ds;
// serialization info hash
hash sih;
// send content encoding hash
*hash seh;
public:
constructor(*hash opts, *softbool do_not_connect) ;
setSerialization(string data = "auto");
setSendEncoding(string enc = "auto");
setContentEncoding(string enc = "auto");
addDefaultHeaders(hash h);
hash getDefaultHeaders();
*string getSendEncoding();
string getSerialization();
hash get(string path, any body, *reference info, *hash hdr);
hash put(string path, any body, *reference info, *hash hdr);
hash post(string path, any body, *reference info, *hash hdr);
hash del(string path, any body, *reference info, *hash hdr);
private nothing prepareMsg(reference body, reference hdr, string ct = "Content-Type");
private nothing preparePath(reference path);
hash doRequest(string m, string path, any body, *reference info, softbool decode_errors = True, *hash hdr);
hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference info, *softbool decode_errors);
private decodeError(hash h, *reference info);
decodeResponse(reference h, *reference info);
};
};
RestClient::RestClient::doRequest
hash doRequest(string m, string path, any body, *reference info, softbool decode_errors=True, *hash hdr)
sends an HTTP request to the REST server and returns the response
RestClient::RestClient
this class provides the REST client API
Definition: RestClient.qm.dox.h:113
RestClient::RestClient::Version
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:166
sprintf
string sprintf(string fmt,...)
RestClient::RestClient::AcceptList
const AcceptList
Accept header list.
Definition: RestClient.qm.dox.h:156
RestClient::RestClient::DataSerializationSupport
const DataSerializationSupport
Data serialization support mapping codes to MIME types and de/serialization functions.
Definition: RestClient.qm.dox.h:118
RestClient::RestClient::del
hash del(string path, any body, *reference info, *hash hdr)
sends an HTTP DELETE request to the REST server and returns the response
RestClient::RestClient::addDefaultHeaders
addDefaultHeaders(hash h)
adds default headers to each request; these headers will be sent in all requests but can be overridde...
RestClient::RestClient::setSendEncoding
setSendEncoding(string enc="auto")
change the data content encoding (compression) option for the object; see EncodingSupport for valid o...
MimeTypeYaml
const MimeTypeYaml
MimeTypeXml
const MimeTypeXml
True
const True
RestClient::RestClient::sendAndDecodeResponse
hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference info, *softbool decode_errors)
sends the outgoing HTTP message and recodes the response to data
RestClient::RestClient::DefaultHeaders
const DefaultHeaders
default HTTP headers (Content-Type is added before sending)
Definition: RestClient.qm.dox.h:172
MimeTypeJsonRpc
const MimeTypeJsonRpc
RestClient::RestClient::getDefaultHeaders
hash getDefaultHeaders()
returns the hash of default headers to sent in all requests
Qore::HTTPClient::constructor
constructor()
MimeTypeJson
const MimeTypeJson
RestClient::RestClient::put
hash put(string path, any body, *reference info, *hash hdr)
sends an HTTP PUT request to the REST server and returns the response
RestClient::RestClient::DataDeserializationSupport
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestClient.qm.dox.h:144
RestClient::RestClient::prepareMsg
private nothing prepareMsg(reference body, reference hdr, string ct="Content-Type")
sets up the Content-Type header and encodes any body for sending
RestClient::RestClient::DataSerializationOptions
const DataSerializationOptions
Data serialization options; this is a hash to simulate a set of strings.
Definition: RestClient.qm.dox.h:184
RestClient::RestClient::Accept
const Accept
Accept header value.
Definition: RestClient.qm.dox.h:163
MimeTypeYamlRpc
const MimeTypeYamlRpc
Qore::HTTPClient
RestClient::RestClient::VersionString
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:169
RestClient::RestClient::getSerialization
string getSerialization()
returns the current data serialization format currently in effect for the object (see DataSerializati...
bzip2
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
RestClient::RestClient::decodeResponse
decodeResponse(reference h, *reference info)
decodes the response
NOTHING
const NOTHING
RestClient::RestClient::getSendEncoding
*string getSendEncoding()
returns the current data content encoding (compression) object or NOTHING if no encoding option is se...
gzip
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
RestClient::RestClient::CompressionThreshold
const CompressionThreshold
default threadhold for data compressions; transfers smaller than this size will not be compressed ...
Definition: RestClient.qm.dox.h:217
RestClient::RestClient::decodeError
private decodeError(hash h, *reference info)
decode any REST errors returned if possible
RestClient::RestClient::post
hash post(string path, any body, *reference info, *hash hdr)
sends an HTTP POST request to the REST server and returns the response
VersionString
const VersionString
RestClient::RestClient::preparePath
private nothing preparePath(reference path)
sets up the path for the HTTP request URI
hash
hash hash(object obj)
RestClient::RestClient::setSerialization
setSerialization(string data="auto")
change the serialization option for the object; see DataSerializationOptions for valid options ...
MimeTypeXmlApp
const MimeTypeXmlApp
RestClient::RestClient::setContentEncoding
setContentEncoding(string enc="auto")
sets the request and desired response encoding for the object; see EncodingSupport for valid options ...
RestClient::RestClient::EncodingSupport
const EncodingSupport
Send content encoding options.
Definition: RestClient.qm.dox.h:198
compress
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)