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 - 2016 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.12 or better
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 // don't use "$" for vars, members, and methods, assume local variable scope
32 
33 
34 
35 
36 
37 }
38 
39 /* Version History - see below in docs
40 */
41 
110 namespace RestClient {
113 class RestClient : public Qore::HTTPClient {
114 
115 public:
116  public :
118  const DataSerializationSupport = {
119  "json": (
120  "ct": MimeTypeJson,
121  "out": \make_json(),
122  ),
123  "yaml": (
124  "ct": MimeTypeYaml,
125  "out": \make_yaml(),
126  ),
127  "xml": (
128  "ct": MimeTypeXml,
129  "out": \make_xmlrpc_value(),
130  ),
131  };
132 
133 
134  const DeserializeYaml = (
135  "code": "yaml",
136  "in": \parse_yaml(),
137  );
138  const DeserializeXmlRpc = (
139  "code": "xml",
140  "in": \parse_xmlrpc_value(),
141  );
142 
144  const DataDeserializationSupport = {
145  MimeTypeJson: (
146  "code": "json",
147  "in": \parse_json(),
148  ),
149  MimeTypeYamlRpc: DeserializeYaml,
150  MimeTypeYaml: DeserializeYaml,
151  MimeTypeXml: DeserializeXmlRpc,
152  MimeTypeXmlApp: DeserializeXmlRpc,
153  };
154 
156  const AcceptList = (
160  );
161 
163  const Accept = AcceptList.join(",");
164 
166  const Version = "1.3";
167 
169  const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
170 
172  const DefaultHeaders = (
173  "Accept": Accept,
174  "User-Agent": RestClient::VersionString,
175  );
176 
178 
184  const DataSerializationOptions = (
185  "auto": True,
186  "xml": True,
187  "json": True,
188  "yaml": True,
189  );
190 
192 
198  const EncodingSupport = (
199  "gzip": (
200  "ce": "gzip",
201  "func": \gzip(),
202  ),
203  "bzip2": (
204  "ce": "bzip2",
205  "func": \bzip2(),
206  ),
207  "deflate": (
208  "ce": "deflate",
209  "func": \compress(),
210  ),
211  "identity": (
212  "ce": NOTHING,
213  ),
214  );
215 
217  const CompressionThreshold = 1024;
218 
219 public:
220 
221  private :
222  // headers to send with every request
223  hash headers;
224  // data serialization code
225  string ds;
226  // serialization info hash
227  hash sih;
228  // send content encoding hash
229  *hash seh;
230 
231 public:
232 
234 
258  constructor(*hash opts, *softbool do_not_connect) ;
259 
260 
262 
273  setSerialization(string data = "auto");
274 
275 
277 
292  setSendEncoding(string enc = "auto");
293 
294 
296 
311  setContentEncoding(string enc = "auto");
312 
313 
315 
329  addDefaultHeaders(hash h);
330 
331 
333 
346  hash getDefaultHeaders();
347 
348 
350 
363  *string getSendEncoding();
364 
365 
367 
376  string getSerialization();
377 
378 
380 
404  hash get(string path, any body, *reference info, *hash hdr);
405 
406 
408 
432  hash put(string path, any body, *reference info, *hash hdr);
433 
434 
436 
460  hash post(string path, any body, *reference info, *hash hdr);
461 
462 
464 
488  hash del(string path, any body, *reference info, *hash hdr);
489 
490 
492  private nothing prepareMsg(reference body, reference hdr, string ct = "Content-Type");
493 
494 
496  private nothing preparePath(reference path);
497 
498 
500 
527  hash doRequest(string m, string path, any body, *reference info, softbool decode_errors = True, *hash hdr);
528 
529 
531  hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference info, *softbool decode_errors);
532 
533 
535  private decodeError(hash h, *reference info);
536 
537 
539  decodeResponse(reference h, *reference info);
540 
541  };
542 };
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:111