Skip to content

Commit

Permalink
Merge pull request quarkusio#39953 from ia3andy/web-doc
Browse files Browse the repository at this point in the history
Introduce Quarkus for the Web documentation
  • Loading branch information
maxandersen committed Apr 15, 2024
2 parents ba15f8e + 6979a5a commit c2c42dd
Show file tree
Hide file tree
Showing 4 changed files with 344 additions and 17 deletions.
34 changes: 33 additions & 1 deletion docs/src/main/asciidoc/http-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ For Servlet support, Quarkus employs a customized Undertow version that operates
When Undertow is present, RESTEasy functions as a Servlet filter.
In its absence, RESTEasy operates directly on Vert.x without involving Servlets.

== Serving Static Resources
== Serving static resources

If you are looking to use Quarkus for a web application, look at the xref:web.adoc[Quarkus for the Web] guide.

=== From the application jar

Expand All @@ -30,6 +32,36 @@ was chosen as it is the standard location for resources in `jar` files as define
Quarkus can be used without Servlet, following this convention allows existing code that places its resources in this
location to function correctly.

[[from-mvnpm]]
=== From mvnpm

If you are using https://mvnpm.org/[mvnpm], as for the following JQuery dependency:

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>org.mvnpm</groupId>
<artifactId>bootstrap</artifactId>
<version>5.3.3</version>
<scope>runtime</scope>
</dependency>
----

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
runtimeOnly("org.mvnpm:bootstrap:5.3.3")
----

You can import it in your HTML like this:
[source,html]
----
<script src="_static/bootstrap/5.3.3/dist/css/bootstrap.min.css"></script>
----


[[from-webjars]]
=== From WebJars

If you are using webjars, like the following JQuery one:
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 39 additions & 16 deletions docs/src/main/asciidoc/qute.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,70 @@ Clone the Git repository: `git clone {quickstarts-clone-url}`, or download an {q

The solution is located in the `qute-quickstart` link:{quickstarts-tree-url}/qute-quickstart[directory].

== Hello World with Jakarta REST
[[serving-templates]]
== Serving Qute templates via http

If you want to use Qute in your Jakarta REST application, you need to add an extension first:
If you want to serve your templates via http:

1. The Qute Web extension allows you to directly serve via http templates located in `src/main/resource/templates/pub/`. In that case you don't need any Java code to "plug" the template, for example, the template `src/main/resource/templates/pub/foo.html` will be served from the paths `/foo` and `/foo.html` by default.
2. For finer control, you can combine it with Quarkus REST to control how your template will be served. All files located in the `src/main/resources/templates` directory and its subdirectories are registered as templates and can be injected in a REST resource.

* either `quarkus-rest-qute` if you are using Quarkus REST (formerly RESTEasy Reactive):
+
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-qute</artifactId>
<groupId>io.quarkiverse.qute.web</groupId>
<artifactId>quarkus-qute-web</artifactId>
</dependency>
----
+

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.quarkus:quarkus-rest-qute")
implementation("io.quarkiverse.qute.web:quarkus-qute-web")
----

NOTE: The Qute Web extension while using the quarkiverse group-id, it is still part of the Quarkus platform.

[[hello-qute-web]]
=== Serving Hello World with Qute

Let's start with a Hello World template:

.src/main/resources/templates/pub/hello.html
[source]
----
<h1>Hello {http:param('name', 'Quarkus')}!</h1> <1>
----
<1> `{http:param('name', 'Quarkus')}` is an expression that is evaluated when the template is rendered (Quarkus is the default value).

NOTE: Templates located in the `pub` directory are served via HTTP. Automatically, no controllers needed. For example, the template src/main/resource/templates/pub/foo.html will be served from the paths /foo and /foo.html by default.

If your application is running, you can open your browser and hit: http://localhost:8080/hello?name=Martin

For more information about Qute Web options, see the https://docs.quarkiverse.io/quarkus-qute-web/dev/index.html[Qute Web guide].

[[hello-qute-rest]]
=== Hello Qute and REST

For finer control, you can combine Qute Web with Quarkus REST or Quarkus RESTEasy to control how your template will be served

* or `quarkus-resteasy-qute` if you are using RESTEasy Classic:
+
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
<artifactId>quarkus-rest</artifactId>
</dependency>
----
+

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
implementation("io.quarkus:quarkus-resteasy-qute")
implementation("io.quarkus:quarkus-rest")
----

We'll start with a very simple template:
A very simple text template:

.hello.txt
[source]
Expand All @@ -73,8 +98,6 @@ Hello {name}! <1>
----
<1> `{name}` is a value expression that is evaluated when the template is rendered.

NOTE: By default, all files located in the `src/main/resources/templates` directory and its subdirectories are registered as templates. Templates are validated during startup and watched for changes in the development mode.

Now let's inject the "compiled" template in the resource class.

.HelloResource.java
Expand Down

0 comments on commit c2c42dd

Please sign in to comment.