Qore RestHandler Module Reference  1.1
RestHandler.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* RestHandler.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 // minimum qore version
26 
27 // require type definitions everywhere
28 
29 // enable all warnings
30 
31 
32 
33 
34 
35 
309 namespace RestHandler {
313 
314 public:
315 private:
316 
317 public:
318 
319  private :
322 
325 
326 public:
327 
329 
342  constructor(hash cx, *hash ah);
343 
344 
346 
356 
357  };
358 
361 
362 public:
363  private :
365  bool deserialized;
366 
367 public:
368 
370  constructor(RestHandler::AbstractRestStreamRequestHandler rsh, HttpListener listener, AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, any body);
371 
372 
373  // callback method for the response header; this calls @ref RestHandler::AbstractRestStreamRequestHandler::getResponseHeaderMessage() and returns the result
384 
385 
387 
397  private nothing recvImpl(hash v);
398 
399 
401 
404  private any sendImpl();
405 
406  };
407 
410 
411 public:
412 private:
413 
414 public:
415 
416  constructor();
417 
418 
420  abstract string name();
421 
423 
439  *AbstractRestClass subClass(string name, hash cx, *hash args);
440 
441 
443  hash handleRequest(HttpListener listener, RestHandler rh, Socket s, *list cl, string mn, hash cx, *hash args);
444 
445 
447  private hash dispatchStream(HttpListener listener, RestHandler rh, Socket s, string mn, *hash ah, hash cx);
448 
449 
451  private hash dispatch(RestHandler rh, string mn, *hash ah, hash cx);
452 
453 
455  private hash unknownSubClassError(string name);
456 
457  };
458 
460 
471 
472 public:
473  public :
475  const Err501 = (
476  "code": 501,
477  "body": "not implemented",
478  );
479 
481  const Methods = (
482  "GET": "get",
483  "POST": "post",
484  "PUT": "put",
485  "DELETE": "del",
486  "OPTIONS": "options",
487  );
488 
490  const MimeDataTypes = (
491  MimeTypeJsonRpc: (
492  "serialize": \makeJSONString(),
493  "deserialize": \parseJSON(),
494  ),
495  MimeTypeYaml: (
496  "serialize": \makeYAML(),
497  "deserialize": \parseYAML(),
498  ),
499 
500  MimeTypeYamlRpc: (
501  "serialize": \makeYAML(),
502  "deserialize": \parseYAML(),
503  ),
504  MimeTypeXml: (
505  "serialize": \makeXMLRPCValueString(),
506  "deserialize": \parseXMLRPCValue(),
507  ),
508  MimeTypeHtml: (
509  "serialize": string (any $body) { return sprintf("<pre>%N</pre>", $body); },
510  ),
511  );
512 
513 public:
514 
515  private :
518 
520  Mutex mx();
521 
522 public:
523 
525 
527  constructor(*AbstractAuthenticator auth);
528 
529 
531  string name();
532 
533 
535 
557  hash handleRequest(HttpListener listener, Socket s, hash cx, hash hdr, *data b);
558 
559 
561  removeRootPath(reference path);
562 
563 
565  requestDeserializationError(hash hdr, hash cx, string body);
566 
567 
569  responseSerializationError(hash cx, *hash aih, hash rv);
570 
571 
573  logInfo(string fmt);
574 
575 
577  logError(string fmt);
578 
579 
581  logDebug(string fmt);
582 
583 
585  addClass(AbstractRestClass cls);
586 
587 
589  static hash makeResponse(int code, any body, *hash hdr);
590  };
591 };
string sprintf(string fmt,...)
hash ch
class hash: name -> AbstractRestClass
Definition: RestHandler.qm.dox.h:517
constructor(hash cx, *hash ah)
creates the object with the given arguments
const MimeTypeYaml
const MimeTypeXml
the RestHandler namespace contains all the objects in the RestHandler module
Definition: RestHandler.qm.dox.h:310
AbstractHttpRequestHandler handler
const MimeTypeJsonRpc
list list(...)
const MimeTypeYamlRpc
private nothing recvImpl(hash v)
callback method for receiving chunked data; this calls RestHandler::AbstractRestStreamRequestHandler:...
hash handleRequest(HttpListener listener, RestHandler rh, Socket s, *list cl, string mn, hash cx, *hash args)
this method is called by the RestHandler class to match the right object with incoming requests ...
*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 "i...
*hash ah
call argument hash
Definition: RestHandler.qm.dox.h:321
the base abstract class for REST stream request handlers
Definition: RestHandler.qm.dox.h:312
the base abstract class for REST handler classes
Definition: RestHandler.qm.dox.h:409
private hash getResponseHeaderMessageImpl()
the base class for handling HTTP chunked requests and responses within the RestHandler infrastructure...
Definition: RestHandler.qm.dox.h:360
hash getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
private any sendImpl()
callback method for sending chunked data; this calls RestHandler::AbstractRestStreamRequestHandler::s...
abstract string name()
this provides the name of the REST class
private hash dispatchStream(HttpListener listener, RestHandler rh, Socket s, string mn, *hash ah, hash cx)
this method is called to dispatch streamed requests on the given object
private hash unknownSubClassError(string name)
throws a "REST-CLASS-ERROR" exception when a request tries to access an unknown subclass ...
private hash dispatch(RestHandler rh, string mn, *hash ah, hash cx)
this method is called to dispatch requests on the given object
const MimeTypeHtml
hash hash(object obj)
hash rhdr
headers to add in the response
Definition: RestHandler.qm.dox.h:324
constructor(RestHandler::AbstractRestStreamRequestHandler rsh, HttpListener listener, AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, any body)
creates the object with the given attributes