QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
Public Member Functions | List of all members
QgsServerApi Class Referenceabstract

Server generic API endpoint abstract base class. More...

#include <qgsserverapi.h>

Inheritance diagram for QgsServerApi:
Inheritance graph
[legend]

Public Member Functions

 QgsServerApi (QgsServerInterface *serverIface)
 Creates a QgsServerApi object. More...
 
virtual ~QgsServerApi ()=default
 
virtual bool accept (const QUrl &url) const
 Returns true if the given url is handled by the API, default implementation checks for the presence of rootPath inside the url path. More...
 
virtual const QString description () const =0
 Returns the API description. More...
 
virtual void executeRequest (const QgsServerApiContext &context) const =0
 Executes a request by passing the given context to the API handlers. More...
 
virtual const QString name () const =0
 Returns the API name. More...
 
virtual const QString rootPath () const =0
 Returns the root path for the API. More...
 
QgsServerInterfaceserverIface () const
 Returns the server interface. More...
 
virtual const QString version () const
 Returns the version of the service. More...
 

Detailed Description

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.

Since
QGIS 3.10

Definition at line 80 of file qgsserverapi.h.

Constructor & Destructor Documentation

◆ QgsServerApi()

QgsServerApi::QgsServerApi ( QgsServerInterface serverIface)

Creates a QgsServerApi object.

Definition at line 24 of file qgsserverapi.cpp.

◆ ~QgsServerApi()

virtual QgsServerApi::~QgsServerApi ( )
virtualdefault

Member Function Documentation

◆ accept()

bool QgsServerApi::accept ( const QUrl &  url) const
virtual

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

Definition at line 29 of file qgsserverapi.cpp.

◆ description()

virtual const QString QgsServerApi::description ( ) const
pure virtual

Returns the API description.

Implemented in QgsServerOgcApi.

◆ executeRequest()

virtual void QgsServerApi::executeRequest ( const QgsServerApiContext context) const
pure virtual

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

Implemented in QgsServerOgcApi.

◆ name()

virtual const QString QgsServerApi::name ( ) const
pure virtual

Returns the API name.

Implemented in QgsServerOgcApi.

◆ rootPath()

virtual const QString QgsServerApi::rootPath ( ) const
pure virtual

Returns the root path for the API.

Implemented in QgsServerOgcApi.

◆ serverIface()

QgsServerInterface * QgsServerApi::serverIface ( ) const

Returns the server interface.

Definition at line 34 of file qgsserverapi.cpp.

◆ version()

virtual const QString QgsServerApi::version ( ) const
inlinevirtual

Returns the version of the service.

Note
the default implementation returns an empty string

Reimplemented in QgsServerOgcApi.

Definition at line 106 of file qgsserverapi.h.


The documentation for this class was generated from the following files:
QgsServer
The QgsServer class provides OGC web services.
Definition: qgsserver.h:48
QgsServerApi
Server generic API endpoint abstract base class.
Definition: qgsserverapi.h:80