Qore RestClient Module Reference: doxygen/qlib/RestClient.qm.dox.h Source File

Qore RestClient Module Reference 1.2

- Main Page
- Related Pages
- Namespaces
- Classes

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 (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
94 namespace RestClient {
97 class RestClient : public Qore::HTTPClient {
98
99 public:
100 public :
102 const DataSerializationSupport = (
103 "json": (
104 "ct": MimeTypeJson,
105 "out": \makeJSONString(),
106 ),
107 "yaml": (
108 "ct": MimeTypeYaml,
109 "out": \makeYAML(),
110 ),
111 "xml": (
112 "ct": MimeTypeXml,
113 "out": \makeXMLRPCValueString(),
114 ),
115 );
116
117
118 const DeserializeYaml = (
119 "code": "yaml",
120 "in": \parseYAML(),
121 );
122 const DeserializeXmlRpc = (
123 "code": "xml",
124 "in": \parseXMLRPCValue(),
125 );
126
128 const DataDeserializationSupport = (
129 MimeTypeJson: (
130 "code": "json",
131 "in": \parseJSON(),
132 ),
133 MimeTypeYamlRpc: DeserializeYaml,
134 MimeTypeYaml: DeserializeYaml,
135 MimeTypeXml: DeserializeXmlRpc,
136 MimeTypeXmlApp: DeserializeXmlRpc,
137 );
138
140 const AcceptList = (
141 MimeTypeYaml, MimeTypeYamlRpc,
142 MimeTypeXml, MimeTypeXmlApp,
143 MimeTypeJsonRpc,
144 );
145
147 const Accept = AcceptList.join(",");
148
150 const Version = "1.2";
151
153 const VersionString = sprintf("Qore-RestClient/%s", RestClient::Version);
154
156 const DefaultHeaders = (
157 "Accept": Accept,
158 "User-Agent": RestClient::VersionString,
159 );
160
162
168 const DataSerializationOptions = (
169 "auto": True,
170 "xml": True,
171 "json": True,
172 "yaml": True,
173 );
174
176
181 const EncodingSupport = (
182 "deflate": (
183 "ce": "deflate",
184 "func": \compress(),
185 ),
186 "bzip2": (
187 "ce": "bzip2",
188 "func": \bzip2(),
189 ),
190 "gzip": (
191 "ce": "gzip",
192 "func": \gzip(),
193 ),
194 );
195
196 public:
197
198 private :
199 // headers to send with every request
200 hash headers;
201 // data serialization code
202 string ds;
203 // serialization info hash
204 hash sih;
205 // send content encoding hash
206 *hash seh;
207
208 public:
209
211
233 constructor(*hash opts, *softbool do_not_connect);
234
235
237
248 setSerialization(string data = "auto");
249
250
252
263 setSendEncoding(string enc = "auto");
264
265
267
276 string getSerialization();
277
278
280
298 hash get(string path, any body, *reference info, *hash hdr);
299
300
302
320 hash put(string path, any body, *reference info, *hash hdr);
321
322
324
342 hash post(string path, any body, *reference info, *hash hdr);
343
344
346
364 hash del(string path, any body, *reference info, *hash hdr);
365
366
368 private nothing prepareMsg(reference body, reference hdr, string ct = "Content-Type");
369
370
372 private nothing preparePath(reference path);
373
374
376
397 hash doRequest(string m, string path, any body, *reference info, *softbool decode_errors, *hash hdr);
398
399
401 decodeResponse(reference h, *reference info);
402
403 };
404 };
RestClient::RestClient
this class provides the REST client API
Definition: RestClient.qm.dox.h:97
sprintf
string sprintf(string fmt,...)
MimeTypeYaml
const MimeTypeYaml
MimeTypeXml
const MimeTypeXml
True
const True
MimeTypeJsonRpc
const MimeTypeJsonRpc
MimeTypeJson
const MimeTypeJson
MimeTypeYamlRpc
const MimeTypeYamlRpc
Qore::HTTPClient
bzip2
binary bzip2(binary bin, softint level=BZ2_DEFAULT_COMPRESSION)
gzip
binary gzip(string str, int level=Z_DEFAULT_COMPRESSION)
VersionString
const VersionString
hash
hash hash(object obj)
MimeTypeXmlApp
const MimeTypeXmlApp
compress
binary compress(string str, int level=Z_DEFAULT_COMPRESSION)