Class: QgsServerApi

Server generic API endpoint abstract base class.

See also

QgsServerOgcApi for an OGC API (aka WFS3) implementation.

An API must have a name and a (possibly empty) version and define a (possibly empty) root path (e.g. “/wfs3”).

The server routing logic will check incoming request URLs by passing them to the API’s accept(url) method, the default implementation performs a simple check for the presence of the API’s root path string in the URL. This simple logic implies that APIs must be registered in reverse order from the most specific to the most generic: given two APIs with root paths ‘/wfs’ and ‘/wfs3’, ‘/wfs3’ must be registered first or it will be shadowed by ‘/wfs’. APIs developers are encouraged to implement a more robust accept(url) logic by making sure that their APIs accept only URLs they can actually handle, if they do, the APIs registration order becomes irrelevant.

After the API has been registered to the server API registry:

class API(QgsServerApi):

  def name(self):
    return "Test API"

  def rootPath(self):
    return "/testapi"

  def executeRequest(self, request_context):
    request_context.response().write(b"\"Test API\"")

server = QgsServer()
api = API(server.serverInterface())
server.serverInterface().serviceRegistry().registerApi(api)

the incoming calls with an URL path starting with the API root path will be routed to the first matching API and executeRequest() method of the API will be invoked.

Added in version 3.10.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: executeRequest()

Class Hierarchy

Inheritance diagram of qgis.server.QgsServerApi

Subclasses

QgsServerOgcApi

QGIS Server OGC API endpoint. QgsServerOgcApi provides the foundation for the new generation of REST-API based OGC services (e.g. WFS3).

class qgis.server.QgsServerApi[source]

Bases: object

__init__(serverIface: QgsServerInterface | None)

Creates a QgsServerApi object

Parameters:

serverIface (Optional[QgsServerInterface])

__init__(a0: QgsServerApi)
Parameters:

a0 (QgsServerApi)

virtual accept(self, url: QUrl) bool[source]

Returns True if the given url is handled by the API, default implementation checks for the presence of rootPath inside the url path.

Parameters:

url (QUrl)

Return type:

bool

description(self) str[source]

Returns the API description

Return type:

str

abstract executeRequest(self, context: QgsServerApiContext)[source]

Executes a request by passing the given context to the API handlers.

Parameters:

context (QgsServerApiContext)

name(self) str[source]

Returns the API name

Return type:

str

rootPath(self) str[source]

Returns the root path for the API

Return type:

str

serverIface(self) QgsServerInterface | None[source]

Returns the server interface

Return type:

Optional[QgsServerInterface]

version(self) str[source]

Returns the version of the service

Note

the default implementation returns an empty string

Return type:

str