Qore RestHandler Module Reference 0.1

- Main Page
- Related Pages
- Namespaces
- Classes

- Namespace List
- Namespace Members

All Classes Namespaces Functions Variables Groups Pages
Classes | Functions | Variables
RestHandler Namespace Reference

the RestHandler namespace contains all the objects in the RestHandler module More...

## Classes
class | AbstractRestClass
| the base abstract class for REST handler classes More...
class | RestHandler
| this is the main handler class to be registered with the HttpServer More...

## Functions
| addClass (AbstractRestClass cls)
| adds a REST class to the handler
| constructor (*AbstractAuthenticator auth)
| create the object optionally with the given AbstractAuthenticator More...
hash | handleRequest (hash cx, hash hdr, *data b)
| called by the HTTP server to handle incoming HTTP requests More...
| logDebug (string fmt)
| default implementation is empty; this method is called with debug log messages; reimplement in subclasses to provide for logging
| logError (string fmt)
| default implementation is empty; this method is called with error log messages; reimplement in subclasses to provide for logging
| logInfo (string fmt)
| default implementation is empty; this method is called with informational log messages; reimplement in subclasses to provide for logging
Mutex | mx ()
| mutex lock
string | name ()
| returns the name of the root REST class
| removeRootPath (reference path)
| default implementation is empty
| requestDeserializationError (hash hdr, hash cx, string body)
| default implementation is empty
| responseSerializationError (hash cx, *hash aih, hash rv)
| default implementation is empty

## Variables
RestHandler::RestHandler | ch
| class hash: name -> AbstractRestClass

## Detailed Description

the RestHandler namespace contains all the objects in the RestHandler module

## Function Documentation

RestHandler::constructor | ( | *AbstractAuthenticator | auth | ) |

create the object optionally with the given AbstractAuthenticator

Parameters

  auth | the authentication object to use to authenticate connections (see AbstractAuthenticator); if no AbstractAuthenticator object is passed, then by default no authentication will be required

hash RestHandler::handleRequest | ( | hash | cx,
|  | hash | hdr,
|  | *data | b
| ) |  |

called by the HTTP server to handle incoming HTTP requests

Requests will be dispatched to REST classes registered with this object

Parameters

  cx | call context hash; this hash will have the following keys: `socket:` the bind address used to bind the listener (`"socket-info"` provides more detailed information) `socket-info`: a hash of socket information for the listening socket (as returned by Qore::Socket::getSocketInfo()) `peer-info`: a hash of socket information for the remote socket (as returned by Qore::Socket::getPeerInfo()) `url:` a hash of broken-down URL information (as returned from parseURL()) `id:` the unique HTTP connection ID `listener-id`: the HTTP server listener ID (see HttpServer::getListenerInfo()) `user:` the current RBAC username (if any)
  hdr | incoming header hash; all keys will be converted to lower-case, additionally the following keys will be present: `method:` the HTTP method received (ie `"GET"`, `"POST"`, etc) `path:` the HTTP path given in the request, after processing by decode_url() (Qore function) `http_version:` the HTTP version number in the request (either `"1.0"` or `"1.1"`)
  b | message body, if any

Returns
  a hash with the following keys:
  - `"code"`: the HTTP return code (see HttpServer::HttpCodes)
  - `"body"`: the message body to return in the response
  - `"close"`: (optional) set this key to True if the connection should be unconditionally closed when the handler returns
  - `"hdr"`: (optional) set this key to a hash of extra header information to be returned with the response