QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerOgcApi class. More...
#include <qgsserverogcapihandler.h>
Public Member Functions | |
virtual | ~QgsServerOgcApiHandler () |
QString | contentTypeForAccept (const QString &accept) const |
Looks for the first ContentType match in the accept header and returns its mime type, returns an empty string if there are not matches. | |
QgsServerOgcApi::ContentType | contentTypeFromRequest (const QgsServerRequest *request) const |
Returns the content type from the request. | |
QList< QgsServerOgcApi::ContentType > | contentTypes () const |
Returns the list of content types this handler can serve, default to JSON and HTML. | |
virtual QgsServerOgcApi::ContentType | defaultContentType () const |
Returns the default response content type in case the client did not specifically ask for any particular content type. | |
virtual std::string | description () const =0 |
Description. | |
virtual void | handleRequest (const QgsServerApiContext &context) const |
Handles the request within its context. | |
std::string | href (const QgsServerApiContext &context, const QString &extraPath=QString(), const QString &extension=QString()) const |
Returns an URL to self, to be used for links to the current resources and as a base for constructing links to sub-resources. | |
void | htmlDump (const json &data, const QgsServerApiContext &context) const |
Writes data as HTML to the response stream in context using a template. | |
void | jsonDump (json &data, const QgsServerApiContext &context, const QString &contentType=QStringLiteral("application/json")) const |
Writes data to the context response stream as JSON (indented if debug is active), an optional contentType can be specified. | |
json | jsonTags () const |
Returns tags as JSON. | |
QgsVectorLayer * | layerFromContext (const QgsServerApiContext &context) const |
Returns a vector layer instance from the "collectionId" parameter of the path in the given context, requires a valid project instance in the context. | |
json | link (const QgsServerApiContext &context, const QgsServerOgcApi::Rel &linkType=QgsServerOgcApi::Rel::self, const QgsServerOgcApi::ContentType contentType=QgsServerOgcApi::ContentType::JSON, const std::string &title="") const |
Builds and returns a link to the resource. | |
json | links (const QgsServerApiContext &context) const |
Returns all the links for the given request context. | |
virtual std::string | linkTitle () const =0 |
Title for the handler link. | |
virtual QgsServerOgcApi::Rel | linkType () const =0 |
Main role for the resource link. | |
virtual std::string | operationId () const =0 |
Returns the operation id for template file names and other internal references. | |
virtual QList< QgsServerQueryStringParameter > | parameters (const QgsServerApiContext &context) const |
Returns a list of query string parameters. | |
virtual QRegularExpression | path () const =0 |
URL pattern for this handler, named capture group are automatically extracted and returned by values() | |
virtual json | schema (const QgsServerApiContext &context) const |
Returns handler information from the context for the OPENAPI description (id, description and other metadata) as JSON. | |
virtual const QString | staticPath (const QgsServerApiContext &context) const |
Returns the absolute path to the base directory where static resources for this handler are stored in the given context. | |
virtual std::string | summary () const =0 |
Summary. | |
virtual QStringList | tags () const |
Tags. | |
virtual const QString | templatePath (const QgsServerApiContext &context) const |
Returns the HTML template path for the handler in the given context. | |
virtual QVariantMap | values (const QgsServerApiContext &context) const |
Analyzes the incoming request context and returns the validated parameter map, throws QgsServerApiBadRequestError in case of errors. | |
void | write (json &data, const QgsServerApiContext &context, const json &htmlMetadata=nullptr) const |
Writes data to the context response stream, content-type is calculated from the context request, optional htmlMetadata for the HTML templates can be specified and will be added as "metadata" to the HTML template variables. | |
void | write (QVariant &data, const QgsServerApiContext &context, const QVariantMap &htmlMetadata=QVariantMap()) const |
Writes data to the context response stream, content-type is calculated from the context request, optional htmlMetadata for the HTML templates can be specified and will be added as "metadata" to the HTML template variables. | |
Static Public Member Functions | |
static json | defaultResponse () |
Returns the defaultResponse as JSON. | |
static QgsVectorLayer * | layerFromCollectionId (const QgsServerApiContext &context, const QString &collectionId) |
Returns a vector layer from the collectionId in the given context. | |
static QString | parentLink (const QUrl &url, int levels=1) |
Returns a link to the parent page up to levels in the HTML hierarchy from the given url, MAP query argument is preserved. | |
Protected Member Functions | |
void | setContentTypes (const QList< QgsServerOgcApi::ContentType > &contentTypes) |
Set the content types to contentTypes. | |
void | setContentTypesInt (const QList< int > &contentTypes) |
Set the content types to contentTypes. | |
The QgsServerOgcApiHandler abstract class represents a OGC API handler to be registered in QgsServerOgcApi class.
Subclasses must override operational and informative methods and define the core functionality in handleRequest() method.
The following methods MUST be implemented:
Optionally, override:
Definition at line 94 of file qgsserverogcapihandler.h.
|
virtual |
Definition at line 63 of file qgsserverogcapihandler.cpp.
QString QgsServerOgcApiHandler::contentTypeForAccept | ( | const QString & | accept | ) | const |
Looks for the first ContentType match in the accept header and returns its mime type, returns an empty string if there are not matches.
Definition at line 85 of file qgsserverogcapihandler.cpp.
QgsServerOgcApi::ContentType QgsServerOgcApiHandler::contentTypeFromRequest | ( | const QgsServerRequest * | request | ) | const |
Returns the content type from the request.
The path file extension is examined first and checked for known mime types, the "Accept" HTTP header is examined next. Fallback to the default content type of the handler if none of the above matches.
QgsServerApiBadRequestError | if the content type of the request is not compatible with the handler ( |
Definition at line 418 of file qgsserverogcapihandler.cpp.
QList< QgsServerOgcApi::ContentType > QgsServerOgcApiHandler::contentTypes | ( | ) | const |
Returns the list of content types this handler can serve, default to JSON and HTML.
In case a specialized type (such as GEOJSON) is supported, the generic type (such as JSON) should not be listed.
Definition at line 74 of file qgsserverogcapihandler.cpp.
|
virtual |
Returns the default response content type in case the client did not specifically ask for any particular content type.
The default implementation returns the first content type returned by contentTypes() or JSON if that list is empty.
Definition at line 68 of file qgsserverogcapihandler.cpp.
|
static |
Returns the defaultResponse as JSON.
Definition at line 544 of file qgsserverogcapihandler.cpp.
|
pure virtual |
Description.
Implemented in QgsServerStaticHandler.
|
virtual |
Handles the request within its context.
Subclasses must implement this methods, and call validate() to extract validated parameters from the request.
QgsServerApiBadRequestError | if the method encounters any error |
Reimplemented in QgsServerStaticHandler.
Definition at line 79 of file qgsserverogcapihandler.cpp.
std::string QgsServerOgcApiHandler::href | ( | const QgsServerApiContext & | context, |
const QString & | extraPath = QString() , |
||
const QString & | extension = QString() |
||
) | const |
Returns an URL to self, to be used for links to the current resources and as a base for constructing links to sub-resources.
context | the current request context |
extraPath | an optional extra path that will be appended to the calculated URL |
extension | optional file extension to add (the dot will be added automatically). |
Definition at line 137 of file qgsserverogcapihandler.cpp.
void QgsServerOgcApiHandler::htmlDump | ( | const json & | data, |
const QgsServerApiContext & | context | ||
) | const |
Writes data as HTML to the response stream in context using a template.
Definition at line 262 of file qgsserverogcapihandler.cpp.
void QgsServerOgcApiHandler::jsonDump | ( | json & | data, |
const QgsServerApiContext & | context, | ||
const QString & | contentType = QStringLiteral( "application/json" ) |
||
) | const |
Writes data to the context response stream as JSON (indented if debug is active), an optional contentType can be specified.
Definition at line 178 of file qgsserverogcapihandler.cpp.
json QgsServerOgcApiHandler::jsonTags | ( | ) | const |
Returns tags as JSON.
Definition at line 554 of file qgsserverogcapihandler.cpp.
|
static |
Returns a vector layer from the collectionId in the given context.
QgsServerApiNotFoundError | if the layer could not be found. |
Definition at line 534 of file qgsserverogcapihandler.cpp.
QgsVectorLayer * QgsServerOgcApiHandler::layerFromContext | ( | const QgsServerApiContext & | context | ) | const |
Returns a vector layer instance from the "collectionId" parameter of the path in the given context, requires a valid project instance in the context.
QgsServerApiNotFoundError | if the layer could not be found |
QgsServerApiImproperlyConfiguredException | if project is not set |
Definition at line 226 of file qgsserverogcapihandler.cpp.
json QgsServerOgcApiHandler::link | ( | const QgsServerApiContext & | context, |
const QgsServerOgcApi::Rel & | linkType = QgsServerOgcApi::Rel::self , |
||
const QgsServerOgcApi::ContentType | contentType = QgsServerOgcApi::ContentType::JSON , |
||
const std::string & | title = "" |
||
) | const |
Builds and returns a link to the resource.
context | request context |
linkType | type of the link (rel attribute), default to SELF |
contentType | content type of the link (default to JSON) |
title | title of the link |
Definition at line 202 of file qgsserverogcapihandler.cpp.
json QgsServerOgcApiHandler::links | ( | const QgsServerApiContext & | context | ) | const |
Returns all the links for the given request context.
The base implementation returns the alternate and self links, subclasses may add other links.
Definition at line 214 of file qgsserverogcapihandler.cpp.
|
pure virtual |
Title for the handler link.
Implemented in QgsServerStaticHandler.
|
pure virtual |
Main role for the resource link.
Implemented in QgsServerStaticHandler.
|
pure virtual |
Returns the operation id for template file names and other internal references.
Implemented in QgsServerStaticHandler.
|
inlinevirtual |
Returns a list of query string parameters.
Depending on the handler, it may be dynamic (per-request) or static.
context | the request context |
Definition at line 122 of file qgsserverogcapihandler.h.
|
static |
Returns a link to the parent page up to levels in the HTML hierarchy from the given url, MAP query argument is preserved.
Definition at line 493 of file qgsserverogcapihandler.cpp.
|
pure virtual |
URL pattern for this handler, named capture group are automatically extracted and returned by values()
Example: "/handlername/(?P<code1>\d{2})/items" will capture "code1" as a named parameter.
Implemented in QgsServerStaticHandler.
|
virtual |
Returns handler information from the context for the OPENAPI description (id, description and other metadata) as JSON.
It may return a NULL JSON object in case the handler does not need to be included in the API.
Definition at line 196 of file qgsserverogcapihandler.cpp.
|
protected |
Set the content types to contentTypes.
Definition at line 568 of file qgsserverogcapihandler.cpp.
|
protected |
Set the content types to contentTypes.
Definition at line 559 of file qgsserverogcapihandler.cpp.
|
virtual |
Returns the absolute path to the base directory where static resources for this handler are stored in the given context.
Definition at line 243 of file qgsserverogcapihandler.cpp.
|
pure virtual |
Summary.
Implemented in QgsServerStaticHandler.
|
inlinevirtual |
Tags.
Definition at line 144 of file qgsserverogcapihandler.h.
|
virtual |
Returns the HTML template path for the handler in the given context.
The template path is calculated from QgsServerSettings's apiResourcesDirectory() as follow: apiResourcesDirectory() + "/ogc/templates/" + context.apiRootPath + operationId + ".html" e.g. for an API with root path "/wfs3" and an handler with operationId "collectionItems", the path will be apiResourcesDirectory() + "/ogc/templates/wfs3/collectionItems.html"
Definition at line 249 of file qgsserverogcapihandler.cpp.
|
virtual |
Analyzes the incoming request context and returns the validated parameter map, throws QgsServerApiBadRequestError in case of errors.
Path fragments from the named groups in the path() regular expression are also added to the map.
Your handleRequest method should call this function to retrieve the parameters map.
QgsServerApiBadRequestError | if validation fails |
Definition at line 39 of file qgsserverogcapihandler.cpp.
void QgsServerOgcApiHandler::write | ( | json & | data, |
const QgsServerApiContext & | context, | ||
const json & | htmlMetadata = nullptr |
||
) | const |
Writes data to the context response stream, content-type is calculated from the context request, optional htmlMetadata for the HTML templates can be specified and will be added as "metadata" to the HTML template variables.
HTML output uses a template engine.
Available template functions: See: https://github.com/pantor/inja#tutorial
Available custom template functions:
Definition at line 106 of file qgsserverogcapihandler.cpp.
void QgsServerOgcApiHandler::write | ( | QVariant & | data, |
const QgsServerApiContext & | context, | ||
const QVariantMap & | htmlMetadata = QVariantMap() |
||
) | const |
Writes data to the context response stream, content-type is calculated from the context request, optional htmlMetadata for the HTML templates can be specified and will be added as "metadata" to the HTML template variables.
HTML output uses a template engine.
Available template functions: See: https://github.com/pantor/inja#tutorial
Available custom template functions:
Definition at line 130 of file qgsserverogcapihandler.cpp.