dsyer / spring-todo-mvc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Todo Spring Boot HTMX demo

This is a small sample application that shows the prototype HTMX integration to build the canonical TodoMVC application using server-side rendering in Spring Boot using Thymeleaf. This sample is for Spring Webflux. There is a Web MVC version on a branch called "webmvc".

Basics

The example is built with progressive enhancement in mind, and also shows different levels of HTMX integration. The very basic application can be run as follows:

$ mvn spring-boot:run

The application is then served from TodoController and uses full page requests if JavaScript is disabled in the browser. If JavaScript is enabled, the hx-boost="true" attribute on the <body /> tag will intercept the server interaction and replace the page with the content returned from the server. You can see this in your browsers developer tools (for Chrome: note that the Network tab contains individual interaction requests rather than full page reloads).

HTMX partials

If the application is run with the htmx profile active (-Phtmx), the HtmxTodoController is registered as well and responds to HTMX’s requests (identified via the HX-Request=true request header, mapped via HtmxTodoController). The controller methods return Flux<Rendering> that render Thymeleaf fragments instead of the entire page. The individually returned <div /> elements returned are then picked up by HTMX running in the browser to update the corresponding parts of the page.

About


Languages

Language:Java 83.1%Language:HTML 16.9%