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);
};
};
sprintf
string sprintf(string fmt,...)
MimeTypeYaml
const MimeTypeYaml
MimeTypeXml
const MimeTypeXml
True
const True
MimeTypeJsonRpc
const MimeTypeJsonRpc
MimeTypeJson
const MimeTypeJson
MimeTypeYamlRpc
const MimeTypeYamlRpc
Qore::HTTPClient
bzip2
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
NOTHING
const NOTHING
gzip
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
VersionString
const VersionString
hash
hash hash(object obj)
MimeTypeXmlApp
const MimeTypeXmlApp
compress
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)
RestClient
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:111