344 namespace RestHandler {
557 abstract string name();
635 const Err501 =
new hash<HttpResponseInfo>((
637 "body":
"not implemented",
646 "OPTIONS":
"options",
653 "serialize": \make_json(),
654 "deserialize": \parse_json(),
657 "serialize": \make_yaml(),
658 "deserialize": \parse_yaml(),
662 "serialize": \make_yaml(),
663 "deserialize": \parse_yaml(),
666 "serialize": \make_xmlrpc_value(),
667 "deserialize": \parse_xmlrpc_value(),
670 "serialize":
string (
auto v) {
671 switch (v.typeCode());
673 return make_xml((
"value": v));
675 "deserialize":
hash (
string xml) {
677 return parse_xmlrpc_value(xml);
679 catch (hash<ExceptionInfo> ex);
688 "serialize":
string (
auto body) {
return sprintf(
"<pre>%N</pre>", body); },
767 hash<HttpResponseInfo>
handleRequest(HttpListenerInterface listener, Socket s,
hash cx,
hash hdr, *data b);
810 class DummyListenerInterface :
public HttpListenerInterface {
813 addUserThreadContext(
hash uctx);
816 auto removeUserThreadContext(*
string k);
822 logError(
string fmt);
logError(string fmt)
default implementation is empty; this method is called with error log messages; reimplement in subcla...
string sprintf(string fmt,...)
const Err501
a hash for a 501 Unimplemented error message
Definition: RestHandler.qm.dox.h:635
hash ch
class hash: name -> AbstractRestClass
Definition: RestHandler.qm.dox.h:696
*int getTimeout()
returns the timeout in milliseconds or NOTHING if no timeout is set
nothing recvImpl(hash v)
callback method for receiving chunked data; this calls RestHandler::AbstractRestStreamRequestHandler:...
string name()
returns the name of the root REST class
*AbstractAuthenticator auth
streamError(hash n_ex)
registers stream errors in the send operation with the stream handler if no error is already present ...
hash cx
call context hash
Definition: RestHandler.qm.dox.h:363
auto handleExternalRequest(string method, string path, *hash body, hash cx={})
processes REST API calls outside the HTTP server
string mime_get_form_urlencoded_string(hash h)
logDebug(string fmt)
default implementation is empty; this method is called with debug log messages; reimplement in subcla...
hash< HttpServer::HttpHandlerResponseInfo > getResponseHeaderMessage()
this method returns the response message description hash by calling getResponseHeaderMessageImpl() ...
constructor(*HttpServer::AbstractAuthenticator auth, RestSchemaValidator::AbstractRestSchemaValidator validator=new NullRestSchemaValidator())
create the object optionally with the given HttpServer::AbstractAuthenticator
AbstractHttpRequestHandler handler
hash< HttpResponseInfo > handleRequest(HttpListenerInterface listener, Socket s, hash cx, hash hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
destructor()
destroys the object and updates the request handler about the status of the persistent connection ...
const MimeDataTypes
supported mime types for de/serializing responses
Definition: RestHandler.qm.dox.h:651
hash< HttpServer::HttpHandlerResponseInfo > 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 ...
requestDeserializationError(hash hdr, hash cx, string body)
default implementation is empty
auto sendImpl()
callback method for sending chunked data; this calls RestHandler::AbstractRestStreamRequestHandler::s...
responseSerializationError(hash cx, *hash aih, hash rv)
default implementation is empty
addClass(AbstractRestClass cls)
adds a REST class to the handler
const MimeTypeFormUrlEncoded
removeRootPath(reference< string > path)
default implementation is empty
logInfo(string fmt)
default implementation is empty; this method is called with informational log messages; reimplement i...
nothing recv(hash v)
this method provides the callback method for receiving chunked data by calling recvImpl() ...
*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 "...
abstract auto sendImpl()
abstract callback method for sending chunked data
*hash ah
call argument hash
Definition: RestHandler.qm.dox.h:369
the base abstract class for REST stream request handlers
Definition: RestHandler.qm.dox.h:354
HttpListenerInterface listener
the base abstract class for REST handler classes
Definition: RestHandler.qm.dox.h:546
static hash makeResponse(int code, auto body, *hash hdr)
creates a hash for an HTTP response with the response code and a literal response message body ...
const Methods
supported HTTP methods
Definition: RestHandler.qm.dox.h:641
the base class for handling HTTP chunked requests and responses within the RestHandler infrastructure...
Definition: RestHandler.qm.dox.h:484
RestSchemaValidator::AbstractRestSchemaValidator validator
REST schema validator.
Definition: RestHandler.qm.dox.h:702
auto send()
this method provides the callback method for sending chunked data by calling sendImpl() ...
*int timeout_ms
socket I/O timeout in milliseconds
Definition: RestHandler.qm.dox.h:375
*code getPersistentClosedNotification()
returns a callable value in case a persistent connection is in progress; NOTHING if not; this method ...
bool isPersistent()
returns True if the connection is persistent; this method in the base class returns False by default ...
abstract string name()
this provides the name of the REST class
abstract hash getResponseHeaderMessageImpl()
this method should return the response message description hash
constructor(RestHandler::AbstractRestStreamRequestHandler n_stream, HttpServer::HttpListenerInterface listener, HttpServer::AbstractHttpRequestHandler handler, Socket s, hash cx, hash hdr, auto body)
creates the object with the given attributes
hash< HttpServer::HttpHandlerResponseInfo > dispatch(RestHandler rh, string mn, *hash ah, hash cx)
this method is called to dispatch requests on the given object
hash< HttpServer::HttpHandlerResponseInfo > getResponseHeaderMessageImpl()
*hash ex
if an exception is raised in a callback then the exception hash is saved here
Definition: RestHandler.qm.dox.h:366
hash rhdr
headers to add in the response
Definition: RestHandler.qm.dox.h:372
abstract nothing recvImpl(hash v)
abstract callback method for receiving chunked data
this is the main handler class to be registered with the HttpServer
Definition: RestHandler.qm.dox.h:630
constructor(hash n_cx, *hash n_ah)
creates the object with the given arguments
hash< HttpServer::HttpHandlerResponseInfo > unknownSubClassError(string n_name)
returns a 404 Not Found response when a request tries to access an unknown subclass ...
hash< auto > mime_parse_form_urlencoded_string(string str)
hash< HttpServer::HttpHandlerResponseInfo > 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
setTimeout(timeout n_timeout_ms)
sets the internal socket I/O timeout value in ms