A Http, REST and File server written using Qt C++.
This project uses the library/code from the below projects:
This project tries to follow the MVC (Model-View-Controller) pattern used by many webservices frameworks
This project was built and tested with Qt v5.5 and Ubuntu. This project requires c++14
- Built-in Authentication. (Incase you want to restrict your rest api to users approved by you only.)
- Session Management. (Set and use session variables like PHP)
- MVC Approach (Create a controller class and add methods for actions)
- Support for large file uploads. (Support uploading files >500MB to remaining space in your harddisk 😉)
- Support for download of large files
- Crash info using DeathHandler
- Built on top of QHttp. (A well tested and live project)
- A TaskManager for managing time consuming tasks which other wise leads to time-out on client side. (Can be used to show progress bar on the client end i.e. Browsers,..etc)
- A Helper class for server-side processing of JQuery Datatables.
- How to Implement Authentication
- How to implement sessions (TODO)
- File management (TODO)
- Complex Examples using databases (TODO)
Lets suppose you want to handle a request: GET /demo/Hello
- Link to the ADNServer Library.
- Create a class named demoController derived from ADNController as shown below.
#include "adncontroller.h"
class demoController : public ADNController
{
};
REGISTER_CONTROLLER(demoController)
- Add a GET Method for Hello
#include "adncontroller.h"
class demoController : public ADNController
{
Q_OBJECT
public:
REGISTER_ACTION QJsonValue getHello(QStringList params,QByteArray data);
};
REGISTER_CONTROLLER(demoController)
#include "democontroller.h"
QJsonValue demoController::getHello(QStringList params, QByteArray data)
{
#ifdef AUTH
if(!Authorizer()->ValidateSession(session()))
{
setResponse(false,"Invalid Session");
return QJsonValue();
}
#endif
Q_UNUSED(params);
Q_UNUSED(data);
QJsonObject retObj;
retObj.insert("Hello","World");
return QJsonValue(retObj);
}
- Add the demoController class to
ACTIVATE_CONTROLLERS
in the main().
ACTIVATE_CONTROLLERS(authController,demoController);
- Start the server.
#include <QCoreApplication>
#include "adnhttpserver.h"
#include "democontroller.h"
#include "authcontroller.h"
#include "filecontroller.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ACTIVATE_CONTROLLERS(authController,demoController);
ADNHttpServer::ADNServer httpserver;
httpserver.start(1992);
int ret = a.exec();
DestroyAuthorizer();
return ret;
}
- Open your browser and go to
localhost:1992/demo/Hello