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 - 2017 Qore Technologies, s.r.o.
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.13 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": MimeTypeJson,
"yaml": MimeTypeYaml,
"xml": MimeTypeXml,
"rawxml": MimeTypeXmlApp,
"url": MimeTypeFormUrlEncoded,
"text": MimeTypeText,
};
const DeserializeYaml = (
"code": "yaml",
"in": \parse_yaml(),
);
const DeserializeXml = (
"code": "xml",
"arg": True,
"in": hash (string xml, reference<string> type) {
try {
on_success type = "xml";
return parse_xmlrpc_value(xml);
}
catch (hash<ExceptionInfo> ex);
},
);
const AcceptList = (
MimeTypeYaml, MimeTypeYamlRpc,
MimeTypeXml, MimeTypeXmlApp,
MimeTypeJsonRpc,
MimeTypeFormUrlEncoded,
MimeTypeText,
);
const Accept = AcceptList.join(",");
const Version = "1.4";
const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
const DefaultHeaders = (
"Accept": Accept,
"User-Agent": RestClient::VersionString,
);
const DataSerializationOptions = (
"auto": True,
"json": True,
"yaml": True,
"rawxml": True,
"xml": True,
"url": True,
"text": 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 content type
string sct;
// send content encoding hash
*hash seh;
// REST schema validator
RestSchemaValidator::AbstractRestSchemaValidator validator;
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, auto body, *reference<hash> info, *hash hdr);
hash put(string path, auto body, *reference<hash> info, *hash hdr);
hash patch(string path, auto body, *reference<hash> info, *hash hdr);
hash post(string path, auto body, *reference<hash> info, *hash hdr);
hash del(string path, auto body, *reference<hash> info, *hash hdr);
RestSchemaValidator::AbstractRestSchemaValidator getValidator();
private:
nothing prepareMsg(string method, string path, reference body, reference<hash> hdr, string ct = "Content-Type");
public:
private:
nothing preparePath(reference<string> path);
public:
hash doRequest(string m, string path, auto body, *reference<hash> info, softbool decode_errors = True, *hash hdr);
hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference<hash> info, *softbool decode_errors);
private:
static decodeError(hash h, *reference<hash> info);
public:
static private;
}; // class RestClient
class RestConnection : public ConnectionProvider::HttpBasedConnection {
public:
public :
hash real_opts;
const Options = HttpConnection::Options + (
"data": True,
"send_encoding": True,
"content_encoding": True,
"swagger": True,
);
const OptionList = Options.keys();
public:
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
private:
RestClient getImpl(bool connect = True, *hash rtopts);
public:
hash getOptions();
*hash getDefaultOptions();
string getType();
static RestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
};
};
ConnectionProvider::AbstractConnection::monitor
bool monitor
RestClient::RestConnection::getType
string getType()
returns "rest"
ConnectionProvider::HttpBasedConnection
sprintf
string sprintf(string fmt,...)
RestClient::RestConnection::getOptions
hash getOptions()
gets options
RestClient::RestConnection::real_opts
hash real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:707
MimeTypeYaml
const MimeTypeYaml
MimeTypeXml
const MimeTypeXml
RestSchemaValidator::AbstractRestSchemaValidator
ConnectionProvider::AbstractConnection::opts
*hash opts
True
const True
ConnectionProvider::AbstractConnection::name
string name
MimeTypeJsonRpc
const MimeTypeJsonRpc
MimeTypeJson
const MimeTypeJson
ConnectionProvider::AbstractConnection::urlh
hash urlh
RestClient::RestConnection::Options
const Options
RestConnection object connection options.
Definition: RestClient.qm.dox.h:710
RestClient::RestConnection::getImpl
RestClient getImpl(bool connect=True, *hash rtopts)
returns a RestClient::RestClient object
MimeTypeFormUrlEncoded
const MimeTypeFormUrlEncoded
RestClient::RestConnection::getDefaultOptions
*hash getDefaultOptions()
returns default options
MimeTypeYamlRpc
const MimeTypeYamlRpc
Qore::HTTPClient
RestClient::RestConnection::constructor
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the RestConnection object
bzip2
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
NOTHING
const NOTHING
gzip
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
type
string type(auto arg)
ConnectionProvider::AbstractConnection::desc
string desc
VersionString
const VersionString
RestClient::RestConnection
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:702
ConnectionProvider::AbstractConnection::url
string url
hash
hash hash(object obj)
RestClient::RestConnection::make
static RestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
MimeTypeXmlApp
const MimeTypeXmlApp
compress
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)
MimeTypeText
const MimeTypeText
RestClient
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:135