PySide6.QtHttpServer.QHttpServer¶
- class QHttpServer¶
QHttpServer
is a simplified API forQAbstractHttpServer
andQHttpServerRouter
.Details
QHttpServer
is used to create a simple HTTP server by registering a range of request handlers.The
route
function can be used to conveniently add rules to the server’sQHttpServerRouter
. To register a handler that is called after every request to further process the response useaddAfterRequestHandler
, but this mechanism only works for routes returningQHttpServerResponse
orQFuture<QHttpServerResponse>
. 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)) { delete tcpserver; return -1; } qDebug() << "Listening on port" << tcpserver->serverPort();
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
Creates an instance of
QHttpServer
with parentparent
.- clearMissingHandler()¶
Resets the handler to the default one that produces replies with status
404 Not Found
.See also
setMissingHandler
- route(rule, callback)¶
- Parameters:
rule – str
callback –
PyCallable
- Return type:
bool
- router()¶
- Return type:
Returns a pointer to the constant router object.