Quarkus QuteServerPages
The goal of this simple extension is to expose Qute templates located in the src/main/resource/templates
directory via HTTP. Automatically, no controllers needed. For example, the template src/main/resource/templates/foo.html
will be served from the paths /qsp/foo
and /qsp/foo.html
by default.
The index.html pages are handled specifically, i.e. they are also served as a "default page" of the containing directory. For example, the template src/main/resource/templates/index.html will be served from the paths /qsp/index , /qsp/index.html and /qsp/ by default.
|
Installation
If you want to use this extension, you need to add the io.quarkiverse.quteserverpages:quarkus-qute-server-pages
extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.quteserverpages</groupId>
<artifactId>quarkus-qute-server-pages</artifactId>
<version>2.0.1.Final</version>
</dependency>
Accessing Data
In a template you can access:
-
@Named
CDI beans; similar to EL; e.g.{cdi:myBean.findItems()}
-
static members of a class annotated with
@TemplateData
-
enums annotated with
@TemplateEnum
-
Namespace Extension Methods in general
-
the current
io.vertx.core.http.HttpServerRequest
via theqsp:
namespace, e.g.{qsp:request.path}
-
the query parameters via the
qsp:
namespace, e.g.{qsp:param('name')}
and{qsp:param('name','Foo')}
Compression Support
If the HTTP compression support is enabled by means of quarkus.http.enable-compression=true
then the response body is compressed if the Content-Type
header derived from the template file name is a compressed media type as configured via quarkus.http.compress-media-types
.
Template Fragments
It is possible to specify the template fragment via the frag
query param.
For example, if there is a template foo.html
that defines a fragment with id bar
then the fragment is served from the path /qsp/foo?frag=bar
.
Content Negotiation
This extension attempts to serve the appropriate template and set the HTTP Content-type
header based on the selected template variant and the value of Accept
header.
For example, if there are templates src/main/resource/templates/foo.html
and src/main/resource/templates/foo.xml
and the client sends the Accept: text/html, application/xml;q=0.9
header then foo.html
is rendeder and the Content-type: text/html
header is set.
qsp:
Namespace
Some useful template extension methods that handle the qsp
namespace are registered automatically.
Name | Description | Example |
---|---|---|
|
Returns the current |
|
|
Returns the first HTTP request query param value with the specified name |
|
|
Return the first HTTP request header value with the specified name |
|
|
Makes it possible to access HTTP header values like properties |
|
HTTP header names are case-insensitive. |
If you need to obtain all values of a specific HTTP header then you can use something similar to {qsp:request.headers.getAll('My-Header')} .
|
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
The root path. All templates will be served relative to this path which is relative to the HTTP root path. If the template name ends with a suffix listed in the For example, a template located in Environment variable: |
string |
|
This regular expression is used to hide template files from the All template file paths are matched, including the versions without suffixes. The matched input is the file path relative
from the By default, the user tags from the Environment variable: |
|
|
The order of the qsp route which handles the templates. Environment variable: |
int |
|
If set to Environment variable: |
boolean |
|