All Classes Namespaces Functions Variables Groups Pages
RestHandler.qm.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* RestHandler.qm Copyright (C) 2013 - 2016 Qore Technologies, sro
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
// minimum qore version
// use new-style
// require type definitions everywhere
// enable all warnings
namespace RestHandler {
class AbstractRestStreamRequestHandler {
public:
private:
public:
private :
hash cx;
*hash ex;
*hash ah;
hash rhdr;
*int timeout_ms;
public:
constructor(hash n_cx, *hash n_ah);
hash getResponseHeaderMessage();
nothing recv(hash v);
any send();
*code getPersistentClosedNotification();
bool isPersistent();
setTimeout(timeout n_timeout_ms);
*int getTimeout();
streamError(hash n_ex);
abstract hash getResponseHeaderMessageImpl();
abstract nothing recvImpl(hash v);
abstract any sendImpl();
};
class RestStreamRequest : public HttpServer::AbstractStreamRequest {
public:
private :
RestHandler::AbstractRestStreamRequestHandler stream;
bool deserialized;
public:
constructor(RestHandler::AbstractRestStreamRequestHandler n_stream, HttpServer::HttpListenerInterface listener, HttpServer::AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, any body) ;
destructor();
// callback method for the response header; this calls @ref RestHandler::AbstractRestStreamRequestHandler::getResponseHeaderMessage() and returns the result
private hash getResponseHeaderMessageImpl();
private nothing recvImpl(hash v);
private any sendImpl();
};
class AbstractRestClass {
public:
private:
public:
constructor();
abstract string name();
*AbstractRestClass subClass(string name, hash cx, *hash args);
hash handleRequest(HttpListenerInterface listener, RestHandler rh, Socket s, *list cl, string mn, hash cx, *hash args);
private hash dispatchStream(HttpListenerInterface listener, RestHandler rh, Socket s, string mn, *hash ah, hash cx);
private hash dispatch(RestHandler rh, string mn, *hash ah, hash cx);
private hash unknownSubClassError(string n_name);
};
class RestHandler : public HttpServer::AbstractHttpRequestHandler,public AbstractRestClass {
public:
public :
const Err501 = (
"code": 501,
"body": "not implemented",
);
const Methods = (
"GET": "get",
"POST": "post",
"PUT": "put",
"DELETE": "del",
"OPTIONS": "options",
);
const MimeDataTypes = (
MimeTypeJsonRpc: (
"serialize": \make_json(),
"deserialize": \parse_json(),
),
MimeTypeYaml: (
"serialize": \make_yaml(),
"deserialize": \parse_yaml(),
),
MimeTypeYamlRpc: (
"serialize": \make_yaml(),
"deserialize": \parse_yaml(),
),
MimeTypeXml: (
"serialize": \make_xmlrpc_value(),
"deserialize": \parse_xmlrpc_value(),
),
MimeTypeHtml: (
"serialize": string (any body) { return sprintf("<pre>%N</pre>", body); },
),
);
public:
private :
hash ch;
Mutex mx();
public:
constructor(*HttpServer::AbstractAuthenticator auth) ;
string name();
hash handleRequest(HttpListenerInterface listener, Socket s, hash cx, hash hdr, *data b);
removeRootPath(reference path);
requestDeserializationError(hash hdr, hash cx, string body);
responseSerializationError(hash cx, *hash aih, hash rv);
logInfo(string fmt);
logError(string fmt);
logDebug(string fmt);
addClass(AbstractRestClass cls);
hash get(hash cx, *hash ah);
static hash makeResponse(int code, any body, *hash hdr);
};
};
RestHandler::RestHandler::logError
logError(string fmt)
default implementation is empty; this method is called with error log messages; reimplement in subcla...
sprintf
string sprintf(string fmt,...)
RestHandler::RestHandler::Err501
const Err501
a hash for a 501 Unimplemented error message
Definition: RestHandler.qm.dox.h:574
HttpServer::AbstractStreamRequest::hdr
hash hdr
RestHandler::RestHandler::ch
hash ch
class hash: name -&gt; AbstractRestClass
Definition: RestHandler.qm.dox.h:616
RestHandler::AbstractRestStreamRequestHandler::getTimeout
*int getTimeout()
returns the timeout in milliseconds or NOTHING if no timeout is set
HttpServer::AbstractStreamRequest
HttpServer::AbstractHttpRequestHandler
RestHandler::RestHandler::name
string name()
returns the name of the root REST class
HttpServer::AbstractHttpRequestHandler::auth
*AbstractAuthenticator auth
MimeTypeYaml
const MimeTypeYaml
RestHandler::AbstractRestStreamRequestHandler::streamError
streamError(hash n_ex)
registers stream errors in the send operation with the stream handler if no error is already present ...
MimeTypeXml
const MimeTypeXml
RestHandler::AbstractRestStreamRequestHandler::cx
hash cx
call context hash
Definition: RestHandler.qm.dox.h:335
RestHandler::RestHandler::makeResponse
static hash makeResponse(int code, any body, *hash hdr)
creates a hash for an HTTP response with the response code and a literal response message body ...
HttpServer::HttpListenerInterface
RestHandler::RestHandler::logDebug
logDebug(string fmt)
default implementation is empty; this method is called with debug log messages; reimplement in subcla...
HttpServer::AbstractStreamRequest::handler
AbstractHttpRequestHandler handler
MimeTypeJsonRpc
const MimeTypeJsonRpc
RestHandler::RestStreamRequest::destructor
destructor()
destroys the object and updates the request handler about the status of the persistent connection ...
RestHandler::RestHandler::constructor
constructor(*HttpServer::AbstractAuthenticator auth)
create the object optionally with the given HttpServer::AbstractAuthenticator
RestHandler::RestHandler::MimeDataTypes
const MimeDataTypes
supported mime types for de/serializing responses
Definition: RestHandler.qm.dox.h:589
RestHandler::AbstractRestStreamRequestHandler::sendImpl
abstract any sendImpl()
abstract callback method for sending chunked data
RestHandler::RestHandler::removeRootPath
removeRootPath(reference path)
default implementation is empty
list
list list(...)
HttpServer::AbstractAuthenticator
RestHandler::RestHandler::requestDeserializationError
requestDeserializationError(hash hdr, hash cx, string body)
default implementation is empty
RestHandler::RestHandler::responseSerializationError
responseSerializationError(hash cx, *hash aih, hash rv)
default implementation is empty
RestHandler::RestHandler::addClass
addClass(AbstractRestClass cls)
adds a REST class to the handler
RestHandler::RestHandler::logInfo
logInfo(string fmt)
default implementation is empty; this method is called with informational log messages; reimplement i...
HttpServer::AbstractStreamRequest::cx
hash cx
HttpServer::AbstractStreamRequest::s
Socket s
MimeTypeYamlRpc
const MimeTypeYamlRpc
RestHandler::RestStreamRequest::recvImpl
private nothing recvImpl(hash v)
callback method for receiving chunked data; this calls RestHandler::AbstractRestStreamRequestHandler:...
RestHandler::AbstractRestStreamRequestHandler::recv
nothing recv(hash v)
this method provides the callback method for receiving chunked data by calling recvImpl() ...
RestHandler::AbstractRestClass::subClass
*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;...
RestHandler::AbstractRestStreamRequestHandler::ah
*hash ah
call argument hash
Definition: RestHandler.qm.dox.h:341
RestHandler::AbstractRestStreamRequestHandler
the base abstract class for REST stream request handlers
Definition: RestHandler.qm.dox.h:326
HttpServer::AbstractStreamRequest::listener
HttpListenerInterface listener
RestHandler::RestStreamRequest::constructor
constructor(RestHandler::AbstractRestStreamRequestHandler n_stream, HttpServer::HttpListenerInterface listener, HttpServer::AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, any body)
creates the object with the given attributes
RestHandler::RestHandler::handleRequest
hash handleRequest(HttpListenerInterface listener, Socket s, hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
RestHandler::AbstractRestClass
the base abstract class for REST handler classes
Definition: RestHandler.qm.dox.h:508
RestHandler::RestStreamRequest::getResponseHeaderMessageImpl
private hash getResponseHeaderMessageImpl()
RestHandler::RestHandler::Methods
const Methods
supported HTTP methods
Definition: RestHandler.qm.dox.h:580
RestHandler::RestStreamRequest
the base class for handling HTTP chunked requests and responses within the RestHandler infrastructure...
Definition: RestHandler.qm.dox.h:455
RestHandler::AbstractRestStreamRequestHandler::timeout_ms
*int timeout_ms
socket I/O timeout in milliseconds
Definition: RestHandler.qm.dox.h:347
RestHandler::AbstractRestStreamRequestHandler::getResponseHeaderMessage
hash getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
RestHandler::AbstractRestStreamRequestHandler::getPersistentClosedNotification
*code getPersistentClosedNotification()
returns a callable value in case a persistent connection is in progress; NOTHING if not; this method ...
RestHandler::RestStreamRequest::sendImpl
private any sendImpl()
callback method for sending chunked data; this calls RestHandler::AbstractRestStreamRequestHandler::s...
RestHandler::AbstractRestClass::dispatchStream
private hash dispatchStream(HttpListenerInterface listener, RestHandler rh, Socket s, string mn, *hash ah, hash cx)
this method is called to dispatch streamed requests on the given object
RestHandler::AbstractRestStreamRequestHandler::isPersistent
bool isPersistent()
returns True if the connection is persistent; this method in the base class returns False by default ...
RestHandler::AbstractRestClass::unknownSubClassError
private hash unknownSubClassError(string n_name)
throws a &quot;REST-CLASS-ERROR&quot; exception when a request tries to access an unknown subclass ...
RestHandler::AbstractRestClass::name
abstract string name()
this provides the name of the REST class
RestHandler::AbstractRestStreamRequestHandler::getResponseHeaderMessageImpl
abstract hash getResponseHeaderMessageImpl()
this method should return the response message description hash
RestHandler::AbstractRestClass::dispatch
private hash dispatch(RestHandler rh, string mn, *hash ah, hash cx)
this method is called to dispatch requests on the given object
RestHandler::AbstractRestStreamRequestHandler::ex
*hash ex
if an exception is raised in a callback then the exception hash is saved here
Definition: RestHandler.qm.dox.h:338
RestHandler::RestHandler::mx
Mutex mx()
mutex lock
MimeTypeHtml
const MimeTypeHtml
hash
hash hash(object obj)
RestHandler::AbstractRestStreamRequestHandler::rhdr
hash rhdr
headers to add in the response
Definition: RestHandler.qm.dox.h:344
RestHandler::AbstractRestStreamRequestHandler::recvImpl
abstract nothing recvImpl(hash v)
abstract callback method for receiving chunked data
RestHandler::RestHandler
this is the main handler class to be registered with the HttpServer
Definition: RestHandler.qm.dox.h:569
RestHandler::AbstractRestStreamRequestHandler::send
any send()
this method provides the callback method for sending chunked data by calling sendImpl() ...
RestHandler::AbstractRestStreamRequestHandler::constructor
constructor(hash n_cx, *hash n_ah)
creates the object with the given arguments
HttpServer::AbstractStreamRequest::body
any body
RestHandler::AbstractRestClass::handleRequest
hash handleRequest(HttpListenerInterface 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 ...
RestHandler::AbstractRestStreamRequestHandler::setTimeout
setTimeout(timeout n_timeout_ms)
sets the internal socket I/O timeout value in ms