- class QHttpServer¶
QHttpServer
is a simplified API forQAbstractHttpServer
andQHttpServerRouter
. More…Synopsis¶
Methods¶
def
__init__()
def
route()
def
router()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
QHttpServer
allows to create a simple Http server by setting a range of request handlers.The
route
function can be used to conveniently add rules to the serversQHttpServerRouter
. To register a handler to be called after every request useaddAfterRequestHandler
and to register a handler for all unhandled requests usesetMissingHandler
.Minimal example:
QHttpServer server; server.route("/", [] () { return "hello world"; }); auto tcpserver = new QTcpServer(); if (!tcpserver->listen() || !server.bind(tcpserver.get())) { delete tcpserver; return -1; } qDebug() << "Listening on port" << tcpserver->serverPort();
Creates an instance of
QHttpServer
with parentparent
.- clearMissingHandler()¶
Resets the handler to the default one that produces replies with status 404 Not Found.
- route(rule, callback)¶
- Parameters:
rule – str
callback –
PyCallable
- Return type:
bool
- router()¶
- Return type:
Returns a pointer to the constant router object.