Webapps
Contents
The webapp service handles requests on the endpoint <server>:<port>/webapp/<app-name>/*.
Introduction
Enonic is capable of delivering web applications natively, without the need for a 3rd party infrastructure. The webapp service provides a flexible platform for building applications of all kinds, from simple static sites to dynamic applications with server-side rendering, real-time updates, and more.
Request pipeline
The webapp pipeline is executed as a subset of the common pipeline:
- webapp.ts
-
Invokes the webapp’s matching HTTP function based on the request method.
- Universal API
-
The webapp may optionally mount contextual APIs which become available within the same URL space (e.g.
<server>:<port>/webapp/<app-name>/_/<app>:<api>). These are mounted via the webapp descriptor.Visit the Universal API section for details on how to implement these.
Implementation
To turn an application into a webapp, place an implementation at /src/main/resources/webapp/webapp.ts that exports one function per HTTP method it handles (GET, POST, etc.) — see HTTP functions.
Once deployed, the webapp is reachable at <server>:<port>/webapp/<app-name>/ (e.g. localhost:8080/webapp/my.webapp/).
| For anything beyond a couple of static endpoints, use the router library for method dispatch, parameter extraction, and pattern matching. |
Descriptor
A webapp descriptor is optional. A webapp consisting of just webapp.ts runs without one.
The descriptor can be used to mount Universal APIs as service points. Place a webapp.yaml alongside webapp.ts and list the APIs in its apis: field:
kind: "WebApp"
apis:
- "ws"
- "app:graphql"
Each listed API becomes reachable as a service point at <server>:<port>/webapp/<app-name>/_/<app>:<api>. See Universal API: Service point for the full mounting rules.
WebSocket and SSE
A webapp can act as a WebSocket channel or a Server-Sent Events stream, like any other HTTP function in XP. But we generally recommend contextually mounting WebSocket and SSE APIs via the API service instead of using the webapp service directly.
Tracing
Each webapp request emits a renderApp trace event with the application key and request path, observable through XP’s standard tracing infrastructure.