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         * For this endpoint we create the model and call the model to view mixin
023         * {@link JStacheViewSupport#toView()}. This approach allows us not to reference the
024         * generated template directly.
025         * @return jstachio powered view
026         */
027        @GET
028        public View hello() {
029                return new ExampleModel("Hello world dropwizard using mixin").toView();
030        }
031
032        /**
033         * For this endpoint we use generated template directly and use a mixin method that
034         * will generate the view from the model.
035         * @return jstachio powered view
036         */
037        @GET
038        @Path("/template")
039        public View template() {
040                return ExampleModelRenderer.of().view(new ExampleModel("Hello dropwizard using template directly."));
041        }
042
043}