Friday January 25, 2019 by Jesús Fernández | Comments
First things first, Happy new year dear Qt users!
I'm sorry, I'm really late :(
Some time ago we decided to avoid repeating the same tedious code to write our own "Simple" Http Servers. So we started writing a Qt HTTP server with several essential features. The word simple is quoted because something planned to be "simple" evolved into a piece of code hard to maintain.
To give few numbers during the last two years, I wrote three times the same code to parse request headers, write response headers, deal with connections, ... And I know, I'm not the only one who did the same (just check GitHub).
To take a look into the code, you can clone it with:
git clone --recursive https://codereview.qt-project.org/qt-labs/qthttpserver
You can manually build it using the last Qt release.
Before listing the features let's show the mandatory hello world example:
#include <QtCore>
#include <QtHttpServer>
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
QHttpServer httpServer;
httpServer.route("/", []() {
return "Hello world";
});
httpServer.listen(QHostAddress::Any);
return app.exec();
}
At this moment it's a qt-labs project, and it's not officially part of the Qt distribution, but at some point, we'll add it.
Some features already implemented are:
I have planned some use-cases for this module:
If you're interested in this project, don't forget to clone it and maybe if you're concerned you can consider contributing or provide some feedback in QTBUG-60105.
Next week Mikhail Svetkin will write more about the routing API. Stay tuned :D
Download the latest release here: www.qt.io/download.
Qt 6 was created to be the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Find webinars, use cases, tutorials, videos & more at resources.qt.io
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.Henkilön Qt (@theqtcompany) jakama julkaisu