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 2013 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.8 or better
// require type definitions everywhere
// enable all warnings
}
/* Version History
* 2013-12-17 v1.1: David Nichols <david@qore.org>
+ updated to use encode_url() before sending HTTP messages
+ add charset=xxx to Content-Type in requests
+ fixed Accept header in requests
* 2013-10-04 v1.0: David Nichols <david@qore.org>
+ the initial version of the RestClient module
*/
namespace RestClient {
class RestClient : public Qore::HTTPClient {
public:
public :
const DataSerializationSupport = (
"json": (
"ct": MimeTypeJson,
"out": \makeJSONString(),
),
"yaml": (
"ct": MimeTypeYaml,
"out": \makeYAML(),
),
"xml": (
"ct": MimeTypeXml,
"out": \makeXMLRPCValueString(),
),
);
const DeserializeYaml = (
"code": "yaml",
"in": \parseYAML(),
);
const DataDeserializationSupport = (
MimeTypeJson: (
"code": "json",
"in": \parseJSON(),
),
MimeTypeYamlRpc: DeserializeYaml,
MimeTypeYaml: DeserializeYaml,
MimeTypeXml: (
"code": "xml",
"in": \parseXMLRPCValue(),
),
);
const AcceptList = (
MimeTypeYaml, MimeTypeYamlRpc,
MimeTypeXml,
MimeTypeJsonRpc,
);
const Accept = AcceptList.join(",");
const Version = "1.0";
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,
);
public:
private :
// headers to send with every request
hash headers;
// data serialization code
string ds;
// serialization info hash
hash sih;
public:
constructor(*hash opts, *softbool do_not_connect);
setSerialization(string data = "auto");
string getSerialization();
hash get(string path, any body, *reference info);
hash put(string path, any body, *reference info);
hash post(string path, any body, *reference info);
hash del(string path, any body, *reference info);
hash doRequest(string m, string path, any body, *reference info, *softbool decode_errors, *hash hdr);
decodeResponse(reference h, *reference info);
};
};
RestClient::RestClient
this class provides the REST client API
Definition: RestClient.qm.dox.h:86
RestClient::RestClient::Version
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:137
sprintf
string sprintf(string fmt,...)
RestClient::RestClient::AcceptList
const AcceptList
Accept header list.
Definition: RestClient.qm.dox.h:127
RestClient::RestClient::DataSerializationSupport
const DataSerializationSupport
Data serialization support mapping codes to MIME types and de/serialization functions.
Definition: RestClient.qm.dox.h:91
RestClient::RestClient::del
hash del(string path, any body, *reference info)
sends an HTTP DELETE request to the REST server and returns the response
MimeTypeYaml
const MimeTypeYaml
MimeTypeXml
const MimeTypeXml
True
const True
RestClient::RestClient::put
hash put(string path, any body, *reference info)
sends an HTTP PUT request to the REST server and returns the response
RestClient::RestClient::DefaultHeaders
const DefaultHeaders
default HTTP headers (Content-Type is added before sending)
Definition: RestClient.qm.dox.h:143
MimeTypeJsonRpc
const MimeTypeJsonRpc
Qore::HTTPClient::constructor
constructor()
MimeTypeJson
const MimeTypeJson
RestClient::RestClient::DataDeserializationSupport
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestClient.qm.dox.h:113
RestClient::RestClient::DataSerializationOptions
const DataSerializationOptions
Data serialization options; this is a hash to similulate a set of strings.
Definition: RestClient.qm.dox.h:155
RestClient::RestClient::Accept
const Accept
Accept header value.
Definition: RestClient.qm.dox.h:134
MimeTypeYamlRpc
const MimeTypeYamlRpc
Qore::HTTPClient
RestClient::RestClient::VersionString
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:140
RestClient::RestClient::getSerialization
string getSerialization()
returns the current data serialization format currently in effect for the object (see DataSerializati...
VersionString
const VersionString
RestClient::RestClient::post
hash post(string path, any body, *reference info)
sends an HTTP POST request to the REST server and returns the response
hash
hash hash(object obj)
RestClient::RestClient::doRequest
hash doRequest(string m, string path, any body, *reference info, *softbool decode_errors, *hash hdr)
sends an HTTP request to the REST server and returns the response
RestClient::RestClient::setSerialization
setSerialization(string data="auto")
change the serialization option for the object; see DataSerializationOptions for valid options ...