PySide6.QtHttpServer.QHttpServer¶
- class QHttpServer¶
QHttpServeris a simplified API forQAbstractHttpServerandQHttpServerRouter. 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¶
QHttpServerallows to create a simple Http server by setting a range of request handlers.The
routefunction can be used to conveniently add rules to the serversQHttpServerRouter. To register a handler to be called after every request useaddAfterRequestHandlerand 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
QHttpServerwith 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.