Hobrasoft httpd server
Embedded HTTP server for Qt and C++
|
Abstract class for processing unified HTTP requests to server's API. More...
#include <abstractcontroller.h>
Public Member Functions | |
AbstractController (HobrasoftHttpd::HttpConnection *parent) | |
Constructor. | |
virtual void | service (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response) |
Request processing. | |
void | setCheckId (bool x) |
If the checkId is set then the exixtence of the item is checked in requests PUT and POST. | |
bool | checkId () const |
Returns the state of checkId. More... | |
Public Member Functions inherited from HobrasoftHttpd::HttpRequestHandler | |
HttpRequestHandler (HttpConnection *parent) | |
Konstruktor. | |
HttpResponse * | response () |
Returns new instance of HttpResponse class. More... | |
Protected Member Functions | |
virtual bool | exists (const QString &id) const |
Check existence of th ID. More... | |
virtual void | serviceOK (HobrasoftHttpd::HttpRequest *request, HobrasoftHttpd::HttpResponse *response, const QVariant &data=QVariant()) |
Sends 200 OK response. More... | |
Protected Member Functions inherited from HobrasoftHttpd::HttpRequestHandler | |
HttpConnection * | connection () const |
Returns pointer to parent HttpConnection class. | |
const HttpSettings * | settings () const |
Returns pointer to HttpSettings used in the HttpServer. | |
Abstract class for processing unified HTTP requests to server's API.
Data are passed in QVariant structures and converted to/from JSON for HTTP transport. The data can be created like this:
Class is a virtual template for unified HTTP requests. Requests are created with stable structure, for example the list of rooms:
The path consist of few components:
Different methods are called to retrieve data:
Default implementation returns error 501. In the derived class all method should be implemeted, which returns some useful data. It can be important to implement also the exists() method - it returns true if the requested ID exists. If it returns false, then the default AbstractController method returned error 404 before your own implementation is called and the connection is closed. Your own implementation can avoid all the care about error states:
The HTML5 event stream can be simply implemented in serviceEvent() method. The method sends responses formated as an event - the data are formated properly and the HTTP headers are supressed. Implementation of event stream can look like this:
Data are passed in QVariant structures and formated in JSON to be send to clients.
Definition at line 114 of file abstractcontroller.h.
|
inline |
Returns the state of checkId.
Definition at line 138 of file abstractcontroller.h.
|
inlineprotectedvirtual |
Check existence of th ID.
The method should be reimplemented in derived classes. Depending of the result the decission is made if the 404 error is sent to the request, of if the reimplemented method will be called (one of serviceId(), serviceIdEvents(), serviceIdDelete()).
Reimplemented in Example::Httpd::ControllerExample.
Definition at line 152 of file abstractcontroller.h.
|
protectedvirtual |
Sends 200 OK response.
data | - data are send instead of default '{ "ok" : true }' |
Definition at line 173 of file abstractcontroller.cpp.