QHttpEngine 0.1.0
Simple and secure HTTP server for Qt applications
|
Handler for invoking slots. More...
#include <QHttpEngine/QObjectHandler>
Public Member Functions | |
QObjectHandler (QObject *parent=0) | |
Create a new QObject handler. | |
![]() | |
QHttpHandler (QObject *parent=0) | |
Base constructor for a handler. | |
void | addRedirect (const QRegExp &pattern, const QString &path) |
Add a redirect for a specific pattern. | |
void | addSubHandler (const QRegExp &pattern, QHttpHandler *handler) |
Add a handler for a specific pattern. | |
void | route (QHttpSocket *socket, const QString &path) |
Route an incoming request. | |
Protected Member Functions | |
virtual void | process (QHttpSocket *socket, const QString &path) |
Reimplementation of QHttpHandler::process() | |
This handler enables incoming requests to invoke a matching slot in a QObject-derived class. The request body is expected to contain parameters encoded as a JSON object. This object is then passed to the slot as a single QVariantMap argument. The slot should return a QVariantMap containing the response.
To use this class, it must be subclassed and one or more slots must be created. The name of the slot will be used to determine the path. For example, the following handler consists of a single method that can be invoked by using the /doSomething
path.
The request body must contain valid JSON which will be decoded and passed to the doSomething() slot as a QVariantMap. The slot should return a QVariantMap which will then be encoded as JSON and written to the socket as the response body.
|
protectedvirtual |
Reimplemented from QHttpHandler.