Pular para o conteúdo principal

Microblog application using Quarkus and template (Qute)



Quarkus 1.1 was released and in the announcement surprisingly a new template extension was mentioned: Qute. Qute was made for Quarkus: it works in dev mode and you can compile to native image using Graal. In this post I will share the application I created to test the template engine.


How Qute works with Quarkus?


Qute works like very other Quarkus extension: convention over configuration and simple setup. It has support for custom tags and the template language is very simple.
You can place templates in resource/templates and then inject them in your code. So if you have:

src/main/resources/templates/productTemplate.html

You can inject it using:

@Inject
io.quarkus.qute.Template productTemplate;

Later you can create instances from this template passing variables and return them in JAX-RS methods. Yes, you can use JAX-RS as controller:
 
    @GET
    @Produces(MediaType.TEXT_HTML)
    public TemplateInstance getProductsHtml() {
        return postsTemplate.data("products", products);
    }

And it is not only about HTML, take a look at Qute guide for more information.


The microblog example


We want to create a page where you can make quick posts, for this a single entity Micropost which will be handled by MicropostResource and rendered by postsTemplate.html. 

Micropost is a Panache entity, which makes very easier to access databases;
MicropostResource is a JAX-RS resource and makes use of Qute templates
postsTemplate.html is a simple HTML file that prints a list of posts

Everything is put together by index.html. See the sources below:

Next steps


The application can evolve to add more quarkus extension and learn more (validation, security, more CRUD operations and so on), but for me it was enough to see Qute in action. For it was a great step towards making microfrontends easier to implement using Quarkus.

The code is on my github.





Comentários

Postagens mais visitadas deste blog

Creating custom Work Item Handler in BPM Suite/jBPM 6

Hi all! In this post I am going to share my experience creating a work item handler for BPM Suite 6.0.3 (which is very similar to jbpm as explained in a previous post ). The Hello World Work Item Handler Let's create a really simple WorkItemHandler just to print "Hello World" in the console. Of course you can implement more feature and make it receive parameters, access database, web services, etc. But in this post we will keep it simple. Really simple. First thing to do is to create a maven project for my WorkItemHandler. Here's the pom.xml of my Maven project: Notice that we are importing jbpm dependency so we can find the java interface that is used to create work item handlers. Now we can start coding. Let's create a class name HelloWorkItemHandler in package org.jugvale.jbpm, here is the simple code: Now we can build our project and go to BPM Suite to configure it so we can use this workitem. Registering the WorkItemHandler UPDATE...

Using the REST Task from jBPM 6

In this post I am going to share my experience using the BPM Suite 6 REST Task. BPM Suite  X jBPM jBPM is a JBoss community project to offer an open source and efficient BPM Suite and BPM Suite is a product created by Red Hat based on jBPM. In this post I will be using BPM Suite because I have it installed already, but what I am going to described should work for jBPM as well.   REST Task  The REST Task is used to invoke a REST resource (or perform an HTTP Request) from your Business Process. You can set the URL, HTTP Method, timeout and credentials from the Process Modeller interface and when the process gets into that task, it will generate a HTTP Request and return the response as String. It is available on the left side pallet under the "Service Tasks" tab: The Target REST Web Service The service we are going to access from our process is a really simple one, that's why it is called simple-hello-rs and it is based on JBoss helloworld-rs qu...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.