.. _web-host-metadata: ================= Web Host Metadata ================= `RFC6415`_ defines how web hosts can expose their metadata through resources. Starting with Nextcloud 21, it's possible to register handlers for HTTP requests to the ``.well-known/*`` route. Writing a handler ----------------- A well known handler is a simple class that implements the ``\OCP\Http\WellKnown\IHandler`` interface. .. code-block:: php 'hello']), ); } } Example webfinger handler ^^^^^^^^^^^^^^^^^^^^^^^^^ The following example shows how an app could react to `RFC6415`_ webfinger requests: .. code-block:: php urlGenerator = $urlGenerator; } public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { if ($service !== 'webfinger') { // Not relevant to this handler return $previousResponse; } $subject = $context->getHttpRequest()->getParam('resource', ''); $href = $this->urlGenerator->linkToRouteAbsolute('myapp.example.test'); // Use the previous response and amend it, if possible $response = $previousResponse; if (!($response instanceof JrdResponse)) { // We override null or any other types $response = new JrdResponse($subject); } return $response->addLink('self', 'application/activity+json', $href); } } Handler registration -------------------- The handler class is registered via the :ref:`bootstrap mechanism` of the ``Application`` class. .. code-block:: php registerWellKnownHandler(Handler::class); } public function boot(IBootContext $context): void {} } .. _`RFC6415`: https://tools.ietf.org/html/rfc6415 .. _`RFC7033`: https://tools.ietf.org/html/rfc7033