Qore RestClient Module Reference  1.4
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 - 2017 Qore Technologies, s.r.o.
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.13 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 
40 /* Version History - see below in docs
41 */
42 
134 namespace RestClient {
137 class RestClient : public Qore::HTTPClient {
138 
139 public:
140  public :
142  const DataSerializationSupport = {
143  "json": MimeTypeJson,
144  "yaml": MimeTypeYaml,
145  "xml": MimeTypeXml,
146  "rawxml": MimeTypeXmlApp,
147  "url": MimeTypeFormUrlEncoded,
148  "text": MimeTypeText,
149  };
150 
151  const DeserializeYaml = (
152  "code": "yaml",
153  "in": \parse_yaml(),
154  );
155  const DeserializeXml = (
156  "code": "xml",
157  "arg": True,
158  "in": hash (string xml, reference<string> type) {
159  try {
160  on_success type = "xml";
161  return parse_xmlrpc_value(xml);
162  }
163  catch (hash<ExceptionInfo> ex);
164 
165  },
166  );
167 
169  const AcceptList = (
174  MimeTypeText,
175  );
176 
178  const Accept = AcceptList.join(",");
179 
181  const Version = "1.4";
182 
184  const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
185 
187  const DefaultHeaders = (
188  "Accept": Accept,
189  "User-Agent": RestClient::VersionString,
190  );
191 
193 
202  const DataSerializationOptions = (
203  "auto": True,
204  "json": True,
205  "yaml": True,
206  "rawxml": True,
207  "xml": True,
208  "url": True,
209  "text": True,
210  );
211 
213 
219  const EncodingSupport = (
220  "gzip": (
221  "ce": "gzip",
222  "func": \gzip(),
223  ),
224  "bzip2": (
225  "ce": "bzip2",
226  "func": \bzip2(),
227  ),
228  "deflate": (
229  "ce": "deflate",
230  "func": \compress(),
231  ),
232  "identity": (
233  "ce": NOTHING,
234  ),
235  );
236 
238  const CompressionThreshold = 1024;
239 
240 public:
241 
242  private :
243  // headers to send with every request
244  hash headers;
245  // data serialization code
246  string ds;
247  // serialization content type
248  string sct;
249  // send content encoding hash
250  *hash seh;
251  // REST schema validator
253 
254 public:
255 
257 
290  constructor(*hash opts, *softbool do_not_connect) ;
291 
292 
294 
305  setSerialization(string data = "auto");
306 
307 
309 
324  setSendEncoding(string enc = "auto");
325 
326 
328 
343  setContentEncoding(string enc = "auto");
344 
345 
347 
361  addDefaultHeaders(hash h);
362 
363 
365 
378  hash getDefaultHeaders();
379 
380 
382 
395  *string getSendEncoding();
396 
397 
399 
408  string getSerialization();
409 
410 
412 
447  hash get(string path, auto body, *reference<hash> info, *hash hdr);
448 
449 
451 
485  hash put(string path, auto body, *reference<hash> info, *hash hdr);
486 
487 
489 
523  hash patch(string path, auto body, *reference<hash> info, *hash hdr);
524 
525 
527 
561  hash post(string path, auto body, *reference<hash> info, *hash hdr);
562 
563 
565 
599  hash del(string path, auto body, *reference<hash> info, *hash hdr);
600 
601 
603 
608 
609 
611 
612 private:
613  nothing prepareMsg(string method, string path, reference body, reference<hash> hdr, string ct = "Content-Type");
614 public:
615 
616 
618 
619 private:
620  nothing preparePath(reference<string> path);
621 public:
622 
623 
625 
663  hash doRequest(string m, string path, auto body, *reference<hash> info, softbool decode_errors = True, *hash hdr);
664 
665 
667  hash sendAndDecodeResponse(*data body, string m, string path, hash hdr, *reference<hash> info, *softbool decode_errors);
668 
669 
671 
672 private:
673  static decodeError(hash h, *reference<hash> info);
674 public:
675 
676 
678  static private;
679 
680 
681  }; // class RestClient
682 
684 
703 
704 public:
705  public :
708 
710  const Options = HttpConnection::Options + (
711  "data": True,
712  "send_encoding": True,
713  "content_encoding": True,
714  "swagger": True,
715  );
716 
717  const OptionList = Options.keys();
718 
719 public:
720 
722 
729  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
730 
731 
733 
740 private:
741  RestClient getImpl(bool connect = True, *hash rtopts);
742 public:
743 
744 
746 
759  hash getOptions();
760 
761 
764 
765 
767  string getType();
768 
769 
771  static RestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
772  };
773 };
string getType()
returns "rest"
string sprintf(string fmt,...)
hash getOptions()
gets options
hash real_opts
real options used when creating an object
Definition: RestClient.qm.dox.h:707
const MimeTypeYaml
const MimeTypeXml
const True
const MimeTypeJsonRpc
const MimeTypeJson
const Options
RestConnection object connection options.
Definition: RestClient.qm.dox.h:710
RestClient getImpl(bool connect=True, *hash rtopts)
returns a RestClient::RestClient object
const MimeTypeFormUrlEncoded
*hash getDefaultOptions()
returns default options
const MimeTypeYamlRpc
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the RestConnection object
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
const NOTHING
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
string type(auto arg)
const VersionString
class for REST HTTP connections; returns RestClient::RestClient objects
Definition: RestClient.qm.dox.h:702
hash hash(object obj)
static RestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
const MimeTypeXmlApp
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)
const MimeTypeText
the RestClient namespace contains all the objects in the RestClient module
Definition: RestClient.qm.dox.h:135