Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions exist-core/src/test/resources/openapi-demo/controller.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0",
"apis": [
{
"spec": "modules/api.json",
"priority": "1"
}
],
"routes": {
"/": { "redirect": "index.html" }
},
"cors": {
"allow-origin": "*"
}
}
58 changes: 58 additions & 0 deletions exist-core/src/test/resources/openapi-demo/modules/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"openapi": "3.0.0",
"info": {
"title": "OpenAPI Demo",
"version": "1.0.0",
"description": "Minimal demo of eXist-db's built-in OpenAPI routing — no Roaster, no controller.xql"
},
"paths": {
"/api/hello": {
"get": {
"summary": "Say hello",
"operationId": "hello:greet",
"responses": {
"200": {
"description": "Greeting message"
}
}
}
},
"/api/hello/{name}": {
"get": {
"summary": "Say hello to someone",
"operationId": "hello:greet-name",
"parameters": [
{
"name": "name",
"in": "path",
"required": true,
"schema": { "type": "string" }
}
],
"responses": {
"200": {
"description": "Personalized greeting"
}
}
}
},
"/api/echo": {
"post": {
"summary": "Echo back the request body",
"operationId": "hello:echo",
"requestBody": {
"content": {
"application/json": {
"schema": { "type": "object" }
}
}
},
"responses": {
"200": {
"description": "Echoed request"
}
}
}
}
}
}
76 changes: 76 additions & 0 deletions exist-core/src/test/resources/openapi-demo/modules/hello.xqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(:
: eXist-db Open Source Native XML Database
: Copyright (C) 2001 The eXist-db Authors
:
: info@exist-db.org
: http://www.exist-db.org
:
: This library is free software; you can redistribute it and/or
: modify it under the terms of the GNU Lesser General Public
: License as published by the Free Software Foundation; either
: version 2.1 of the License, or (at your option) any later version.
:
: This library is distributed in the hope that it will be useful,
: but WITHOUT ANY WARRANTY; without even the implied warranty of
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
: Lesser General Public License for more details.
:
: You should have received a copy of the GNU Lesser General Public
: License along with this library; if not, write to the Free Software
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
:)
xquery version "3.1";

(:~
: Demo handler module for OpenAPI-native routing.
:
: No Roaster import. No controller.xql. Just a plain XQuery module
: with functions that accept a $request map and return data.
:
: The module namespace URI follows the convention:
: http://exist-db.org/apps/{prefix}
: where {prefix} matches the operationId prefix in api.json.
:)
module namespace hello = "http://exist-db.org/apps/hello";

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "json";
declare option output:media-type "application/json";

(:~
: Simple greeting.
: GET /api/hello
:)
declare function hello:greet($request as map(*)) {
map {
"message": "Hello from eXist-db's built-in OpenAPI routing!",
"method": $request?method,
"path": $request?path,
"note": "No Roaster. No controller.xql. Just controller.json + api.json + this module."
}
};

(:~
: Personalized greeting.
: GET /api/hello/{name}
:)
declare function hello:greet-name($request as map(*)) {
let $name := $request?parameters?name
return map {
"message": "Hello, " || $name || "!",
"parameters": $request?parameters
}
};

(:~
: Echo the request.
: POST /api/echo
:)
declare function hello:echo($request as map(*)) {
map {
"echo": true(),
"method": $request?method,
"body": $request?body,
"parameters": $request?parameters
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<forward pattern="/rest" servlet="EXistServlet"/>
<forward pattern="/xmlrpc" servlet="org.exist.xmlrpc.RpcServlet"/>
<forward pattern=".*bfResources/" servlet="ResourceServlet"/>
<forward pattern="/api/packages" servlet="PackageManagementServlet"/>

<root pattern="/db.*" path="xmldb:exist:///db"/>
<root pattern=".*" path="xmldb:exist:///db/apps"/>
Expand Down
6 changes: 6 additions & 0 deletions exist-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>exist-services</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>exist-start</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions exist-distribution/src/main/config/conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@
EXQuery RESTXQ trigger to load the RESTXQ Registry at startup time
-->
<trigger class="org.exist.extensions.exquery.restxq.impl.RestXqStartupTrigger"/>

<!--
OpenAPI startup trigger: scans /db/apps/ for controller.json
files and registers routes for built-in OpenAPI routing.
-->
<trigger class="org.exist.http.openapi.OpenApiStartupTrigger"/>

<!--
AutoDeploymentTrigger will install any .xar application package it finds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

<!-- RESTXQ -->
<forward pattern="/restxq/" servlet="RestXqServlet"/>

<!-- Package Management API (built-in, no XAR dependency) -->
<forward pattern="/api/packages" servlet="PackageManagementServlet"/>

<!-- betterFORM resource-servlet -->
<forward pattern=".*bfResources/" servlet="ResourceServlet"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
<forward pattern="/images" servlet="ScaleImageJAI"/>
-->

<!-- Package Management API (built-in, no XAR dependency) -->
<forward pattern="/api/packages" servlet="PackageManagementServlet"/>

<!-- OpenAPI routing for apps using controller.json (PoC: /openapi/ prefix) -->
<forward pattern="/openapi/" servlet="OpenApiServlet"/>

<!-- The JMX status servlet used to monitor the db -->
<forward pattern="/status" servlet="JMXServlet"/>

Expand Down
32 changes: 32 additions & 0 deletions exist-jetty-config/src/main/resources/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,38 @@
<load-on-startup>4</load-on-startup>
</servlet>

<!--
PackageManagementServlet provides a built-in REST API for package
management that does not depend on any XAR package.
-->
<servlet>
<servlet-name>PackageManagementServlet</servlet-name>
<servlet-class>org.exist.http.servlets.PackageManagementServlet</servlet-class>
<init-param>
<param-name>use-default-user</param-name>
<param-value>false</param-value>
</init-param>
<multipart-config>
<max-file-size>268435456</max-file-size>
<max-request-size>268435456</max-request-size>
</multipart-config>
<load-on-startup>3</load-on-startup>
</servlet>

<!--
OpenApiServlet provides built-in OpenAPI routing for apps that
use controller.json instead of controller.xql.
-->
<servlet>
<servlet-name>OpenApiServlet</servlet-name>
<servlet-class>org.exist.http.openapi.OpenApiServlet</servlet-class>
<init-param>
<param-name>use-default-user</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>

<!--
XQueryServlet generates HTML from an XQuery file.
-->
Expand Down
38 changes: 38 additions & 0 deletions exist-services/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.exist-db</groupId>
<artifactId>exist-parent</artifactId>
<version>7.0.0-SNAPSHOT</version>
<relativePath>../exist-parent</relativePath>
</parent>

<artifactId>exist-services</artifactId>
<packaging>jar</packaging>

<name>eXist-db Platform Services</name>
<description>
Built-in HTTP services for the eXist-db platform: package management REST API
and OpenAPI-based routing. These services are compiled into the platform and
require no XAR package installation.
</description>

<dependencies>
<!-- exist-core provides all needed APIs + transitive deps (jackson, pkg-repo, etc.) -->
<dependency>
<groupId>org.exist-db</groupId>
<artifactId>exist-core</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
</dependencies>
</project>
Loading
Loading