PySide6.QtHttpServer.QHttpServerRouter¶
- class QHttpServerRouter¶
- Provides functions to bind a URL to a - ViewHandler. More…- Synopsis¶- Methods¶- def - __init__()
- def - addConverter()
- def - converters()
- def - handleRequest()
 - 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¶- QHttpServerRouteris a class to distribute http requests to their respective handlers with a rule based system.- You can register new - QHttpServerRouterRules, that represent a request path and the respective handler. Variable parts in the route can be specified with placeholder in the request path. The handler gets the placeholders value as a QRegularExpressionMatch. The arguments can be of any type for which a- converteris available. The handler creation can be simplified with- bindCaptured. A- QHttpServerRouterinstance must not be modifed by its rules.- Note - This is a low-level routing API for an HTTP server. - Minimal example: - auto pageView = [] (const quint64 page) { qDebug() << "page" << page; }; using ViewHandler = decltype(pageView); QHttpServerRouter router; // register callback pageView on request "/page/<number>" // for example: "/page/10", "/page/15" router.addRule<ViewHandler>( new QHttpServerRouterRule("/page/", [=] (QRegularExpressionMatch &match, const QHttpServerRequest &, QHttpServerResponder &&) { auto boundView = QHttpServerRouterRule::bindCaptured(pageView, match); // it calls pageView boundView(); })); - __init__(server)¶
- Parameters:
- server – - QAbstractHttpServer
 
 - Creates a - QHttpServerRouterobject with default converters.- See also - Adds a new converter for - metaTypethat can be parsed with- regexp. Having a converter for a- metaTypeenables to use this type in a path pattern of a- QHttpServerRouterRule. The regular expression is used to parse parameters of type- metaTypefrom the path pattern.- If there is already a converter of type - metaType, that converter’s regexp is replaced with- regexp.- See also - clearConverters()¶
 - Removes all converters. - converters()¶
- Return type:
- Dictionary with keys of type .QMetaType and values of type QString. 
 
 - handleRequest(request, responder)¶
- Parameters:
- request – - QHttpServerRequest
- responder – - QHttpServerResponder
 
- Return type:
- bool 
 
 - Handles each new - requestfor the HTTP server using- responder.- Iterates through the list of rules to find the first that matches, then executes this rule, returning - true. Returns- falseif no rule matches the request.- Removes the converter for type - metaType.- See also