001package io.jstach.opt.dropwizard.example; 002 003import io.dropwizard.views.common.View; 004import io.jstach.opt.dropwizard.JStacheViewSupport; 005import jakarta.ws.rs.GET; 006import jakarta.ws.rs.Path; 007import jakarta.ws.rs.Produces; 008import jakarta.ws.rs.core.MediaType; 009 010/** 011 * Dropwizard JAXRS example resource highlighting JStachio integration. 012 * 013 * @author agentgt 014 * 015 */ 016@Path("/example") 017@Produces(MediaType.TEXT_HTML) 018@SuppressWarnings("exports") 019public class ExampleResource { 020 021 /** 022 * Do nothing constructor. 023 */ 024 public ExampleResource() { 025 } 026 027 /** 028 * For this endpoint we create the model and call the model to view mixin 029 * {@link JStacheViewSupport#toView()}. This approach allows us not to reference the 030 * generated template directly. 031 * @return jstachio powered view 032 */ 033 @GET 034 public View hello() { 035 return new ExampleModel("Hello world dropwizard using mixin").toView(); 036 } 037 038 /** 039 * For this endpoint we use generated template directly and use a mixin method that 040 * will generate the view from the model. 041 * @return jstachio powered view 042 */ 043 @GET 044 @Path("/template") 045 public View template() { 046 return ExampleModelRenderer.of().view(new ExampleModel("Hello dropwizard using template directly.")); 047 } 048 049}