Qore RestClient Module Reference  1.0
 All Classes Namespaces Functions Variables Groups Pages
RestClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file RestClient.qm Qore user module for calling REST services
3 
4 /* RestClient.qm Copyright 2013 Qore Technologies, sro
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23 */
24 
25 // this module requires Qore 0.8.8 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 
34 
35 }
36 
37 /* Version History
38  * 2013-10-04 v1.0: David Nichols <david@qore.org>
39  + the initial version of the RestClient module
40 */
41 
77 namespace RestClient {
80 class RestClient : public Qore::HTTPClient {
81 
82 public:
83  public :
86  "json": (
87  "ct": MimeTypeJson,
88  "out": \makeJSONString(),
89  ),
90  "yaml": (
91  "ct": MimeTypeYaml,
92  "out": \makeYAML(),
93  ),
94  "xml": (
95  "ct": MimeTypeXml,
96  "out": \makeXMLRPCValueString(),
97  ),
98  );
99 
100 
101  const DeserializeYaml = (
102  "code": "yaml",
103  "in": \parseYAML(),
104  );
105 
108  MimeTypeJson: (
109  "code": "json",
110  "in": \parseJSON(),
111  ),
112  MimeTypeYamlRpc: DeserializeYaml,
113  MimeTypeYaml: DeserializeYaml,
114  MimeTypeXml: (
115  "code": "xml",
116  "in": \parseXMLRPCValue(),
117  ),
118  );
119 
121  const AcceptList = (
123  MimeTypeXml,
125  );
126 
128  const Accept = AcceptList.join(",");
129 
131  const Version = "1.0";
132 
134  const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
135 
137  const DefaultHeaders = (
138  "Accept": MimeTypeYamlRpc,
139  "User-Agent": RestClient::VersionString,
140  );
141 
143 
150  "auto": True,
151  "xml": True,
152  "json": True,
153  "yaml": True,
154  );
155 
156 public:
157 
158  private :
159  // headers to send with every request
160  hash headers;
161  // data serialization code
162  string ds;
163  // serialization info hash
164  hash sih;
165 
166 public:
167 
169 
188  constructor(*hash opts, *softbool do_not_connect);
189 
190 
192 
203  setSerialization(string data = "auto");
204 
205 
207 
216  string getSerialization();
217 
218 
220 
237  hash get(string path, any body, *reference info);
238 
239 
241 
258  hash put(string path, any body, *reference info);
259 
260 
262 
279  hash post(string path, any body, *reference info);
280 
281 
283 
300  hash del(string path, any body, *reference info);
301 
302 
304 
325  hash doRequest(string m, string path, any body, *reference info, *softbool decode_errors, *hash hdr);
326 
327 
328  decodeResponse(reference h, *reference info);
329 
330  };
331 };
this class provides the REST client API
Definition: RestClient.qm.dox.h:80
const Version
RestClient Version.
Definition: RestClient.qm.dox.h:131
string sprintf(string fmt,...)
const AcceptList
Accept header list.
Definition: RestClient.qm.dox.h:121
const DataSerializationSupport
Data serialization support mapping codes to MIME types and de/serialization functions.
Definition: RestClient.qm.dox.h:85
hash del(string path, any body, *reference info)
sends an HTTP DELETE request to the REST server and returns the response
const MimeTypeYaml
const MimeTypeXml
const True
hash put(string path, any body, *reference info)
sends an HTTP PUT request to the REST server and returns the response
const DefaultHeaders
default HTTP headers (Content-Type is added before sending)
Definition: RestClient.qm.dox.h:137
const MimeTypeJsonRpc
const MimeTypeJson
const DataDeserializationSupport
Data deserialization support MIME types to codes and de/serialization functions.
Definition: RestClient.qm.dox.h:107
const DataSerializationOptions
Data serialization options; this is a hash to similulate a set of strings.
Definition: RestClient.qm.dox.h:149
const Accept
Accept header value.
Definition: RestClient.qm.dox.h:128
const MimeTypeYamlRpc
const VersionString
RestClient Version String.
Definition: RestClient.qm.dox.h:134
string getSerialization()
returns the current data serialization format currently in effect for the object (see DataSerializati...
const VersionString
hash post(string path, any body, *reference info)
sends an HTTP POST request to the REST server and returns the response
hash hash(object obj)
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
setSerialization(string data="auto")
change the serialization option for the object; see DataSerializationOptions for valid options ...