Interface Renderable

  • All Known Implementing Classes:
    Markup, ResponseChunks, ServerSentEvents

    public interface Renderable
    A renderable object, that can be given to Context.render(Object).

    A Renderer for this type is provided by Ratpack core, that simply delegates to render(Context). An alternative to providing a Renderer implementation for a type is to make the type implement this interface.

    
     import ratpack.core.handling.Context;
     import ratpack.core.render.Renderable;
     import ratpack.test.embed.EmbeddedApp;
    
     import static org.junit.jupiter.api.Assertions.*;
    
     public class Example {
       static class Thing implements Renderable {
         public void render(Context context) {
           context.render("thing!");
         }
       }
    
       static void main(String... args) throws Exception {
         EmbeddedApp.fromHandler(ctx ->
           ctx.render(new Thing())
         ).test(httpClient ->
           assertEquals("thing!", httpClient.getText())
         );
       }
     }
     

    An alternative to making a type implement this interface, is implementing a Renderer for it.

    • Method Detail

      • render

        void render​(Context context)
             throws Exception
        Render this object to the response.
        Parameters:
        context - the request handling context
        Throws:
        Exception - any