Qore RestHandler Module Reference  0.1
 All Classes Namespaces Functions Variables Groups Pages
RestHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* RestHandler.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 /* Version History
37  * 2013-10-04 v1.0: David Nichols <david@qore.org>
38  + the initial version of the RestHandler module
39 */
40 
272 namespace RestHandler {
276 
277 public:
278 private:
279 
280 public:
281 
282  constructor();
283 
284 
286  abstract string name();
287 
289 
305  *AbstractRestClass subClass(string name, hash cx, *hash args);
306 
307 
309  hash handleRequest(RestHandler rh, *list cl, string mn, hash cx, *hash args);
310 
311 
313 
314 private:
315  hash dispatch(RestHandler rh, *string oname, string mn, *hash ah, hash cx);
316 public:
317 
318 
320 
321 private:
322  hash unknownSubClassError(string name);
323 public:
324 
325  };
326 
328 
339 
340 public:
341  public :
343  const Err501 = (
344  "code": 501,
345  "body": "not implemented",
346  );
347 
349  const Methods = (
350  "GET": "get",
351  "POST": "post",
352  "PUT": "put",
353  "DELETE": "del",
354  );
355 
357  const MimeDataTypes = (
358  MimeTypeJsonRpc: (
359  "serialize": \makeJSONString(),
360  "deserialize": \parseJSON(),
361  ),
362  MimeTypeYaml: (
363  "serialize": \makeYAML(),
364  "deserialize": \parseYAML(),
365  ),
366 
367  MimeTypeYamlRpc: (
368  "serialize": \makeYAML(),
369  "deserialize": \parseYAML(),
370  ),
371  MimeTypeXml: (
372  "serialize": \makeXMLRPCValueString(),
373  "deserialize": \parseXMLRPCValue(),
374  ),
375  MimeTypeHtml: (
376 
377 public:
378  ),
379  );
380  }
381 
382  private :
384  hash ch;
385 
387  Mutex mx();
388 
389 public:
390 
392 
394  constructor(*AbstractAuthenticator auth);
395 
396 
398  string name();
399 
400 
402 
424  hash handleRequest(hash cx, hash hdr, *data b);
425 
426 
428  removeRootPath(reference path);
429 
430 
432  requestDeserializationError(hash hdr, hash cx, string body);
433 
434 
437 
438 
440  logInfo(string fmt);
441 
442 
444  logError(string fmt);
445 
446 
448  logDebug(string fmt);
449 
450 
453 
454 
456  static hash makeResponse(int code, any body, *hash hdr);
457  };
458 };
constructor(*AbstractAuthenticator auth)
create the object optionally with the given AbstractAuthenticator
logDebug(string fmt)
default implementation is empty; this method is called with debug log messages; reimplement in subcla...
const Err501
a hash for a 501 Unimplemented error message
Definition: RestHandler.qm.dox.h:343
const MimeTypeYaml
const MimeTypeXml
logInfo(string fmt)
default implementation is empty; this method is called with informational log messages; reimplement i...
const MimeTypeJsonRpc
const MimeDataTypes
supported mime types for de/serializing responses
Definition: RestHandler.qm.dox.h:357
removeRootPath(reference path)
default implementation is empty
list list(...)
responseSerializationError(hash cx, *hash aih, hash rv)
default implementation is empty
logError(string fmt)
default implementation is empty; this method is called with error log messages; reimplement in subcla...
const MimeTypeYamlRpc
RestHandler::RestHandler ch
class hash: name -&gt; AbstractRestClass
addClass(AbstractRestClass cls)
adds a REST class to the handler
hash unknownSubClassError(string name)
throws a &quot;REST-CLASS-ERROR&quot; exception when a request tries to access an unknown subclass ...
string name()
returns the name of the root REST class
*AbstractRestClass subClass(string name, hash cx, *hash args)
this method will be called to find a sub-class (ie with GET /invoices/1 - if this class represents &quot;...
hash handleRequest(RestHandler rh, *list cl, string mn, hash cx, *hash args)
this method is called by the RestHandler class to match the right object with incoming requests ...
the base abstract class for REST handler classes
Definition: RestHandler.qm.dox.h:275
requestDeserializationError(hash hdr, hash cx, string body)
default implementation is empty
const Methods
supported HTTP methods
Definition: RestHandler.qm.dox.h:349
hash dispatch(RestHandler rh, *string oname, string mn, *hash ah, hash cx)
this method is called to dispatch requests on the given object
abstract string name()
this provides the name of the REST class
const MimeTypeHtml
hash handleRequest(hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
hash hash(object obj)
Mutex mx()
mutex lock
this is the main handler class to be registered with the HttpServer
Definition: RestHandler.qm.dox.h:338