Qore RestClient Module Reference  1.3
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 (C) 2013 - 2014 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.11 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 
34 
35 }
36 
37 /* Version History - see below in docs
38 */
39 
106 namespace RestClient {
109 class RestClient : public Qore::HTTPClient {
110 
111 public:
112  public :
114  const DataSerializationSupport = (
115  "json": (
116  "ct": MimeTypeJson,
117  "out": \makeJSONString(),
118  ),
119  "yaml": (
120  "ct": MimeTypeYaml,
121  "out": \makeYAML(),
122  ),
123  "xml": (
124  "ct": MimeTypeXml,
125  "out": \makeXMLRPCValueString(),
126  ),
127  );
128 
129 
130  const DeserializeYaml = (
131  "code": "yaml",
132  "in": \parseYAML(),
133  );
134  const DeserializeXmlRpc = (
135  "code": "xml",
136  "in": \parseXMLRPCValue(),
137  );
138 
140  const DataDeserializationSupport = (
141  MimeTypeJson: (
142  "code": "json",
143  "in": \parseJSON(),
144  ),
145  MimeTypeYamlRpc: DeserializeYaml,
146  MimeTypeYaml: DeserializeYaml,
147  MimeTypeXml: DeserializeXmlRpc,
148  MimeTypeXmlApp: DeserializeXmlRpc,
149  );
150 
152  const AcceptList = (
156  );
157 
159  const Accept = AcceptList.join(",");
160 
162  const Version = "1.3";
163 
165  const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
166 
168  const DefaultHeaders = (
169  "Accept": Accept,
170  "User-Agent": RestClient::VersionString,
171  );
172 
174 
180  const DataSerializationOptions = (
181  "auto": True,
182  "xml": True,
183  "json": True,
184  "yaml": True,
185  );
186 
188 
194  const EncodingSupport = (
195  "gzip": (
196  "ce": "gzip",
197  "func": \gzip(),
198  ),
199  "bzip2": (
200  "ce": "bzip2",
201  "func": \bzip2(),
202  ),
203  "deflate": (
204  "ce": "deflate",
205  "func": \compress(),
206  ),
207  "identity": (
208  "ce": NOTHING,
209  ),
210  );
211 
213  const CompressionThreshold = 1024;
214 
215 public:
216 
217  private :
218  // headers to send with every request
219  hash headers;
220  // data serialization code
221  string ds;
222  // serialization info hash
223  hash sih;
224  // send content encoding hash
225  *hash seh;
226 
227 public:
228 
230 
254  constructor(*hash opts, *softbool do_not_connect);
255 
256 
258 
269  setSerialization(string data = "auto");
270 
271 
273 
288  setSendEncoding(string enc = "auto");
289 
290 
292 
307  setContentEncoding(string enc = "auto");
308 
309 
311 
325  addDefaultHeaders(hash h);
326 
327 
329 
342  hash getDefaultHeaders();
343 
344 
346 
359  *string getSendEncoding();
360 
361 
363 
372  string getSerialization();
373 
374 
376 
394  hash get(string path, any body, *reference info, *hash hdr);
395 
396 
398 
416  hash put(string path, any body, *reference info, *hash hdr);
417 
418 
420 
438  hash post(string path, any body, *reference info, *hash hdr);
439 
440 
442 
460  hash del(string path, any body, *reference info, *hash hdr);
461 
462 
464  private nothing prepareMsg(reference body, reference hdr, string ct = "Content-Type");
465 
466 
468  private nothing preparePath(reference path);
469 
470 
472 
493  hash doRequest(string m, string path, any body, *reference info, *softbool decode_errors, *hash hdr);
494 
495 
497  hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference info, *softbool decode_errors);
498 
499 
501  private decodeError(hash h, *reference info);
502 
503 
505  decodeResponse(reference h, *reference info);
506 
507  };
508 };
string sprintf(string fmt,...)
const MimeTypeYaml
const MimeTypeXml
const True
const MimeTypeJsonRpc
const MimeTypeJson
const MimeTypeYamlRpc
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
const NOTHING
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
const VersionString
hash hash(object obj)
const MimeTypeXmlApp
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:107