Interface ResponseBody

All Known Subinterfaces:
WebResponseBody

public interface ResponseBody

Represents the payload body of a server response in a server exchange.

The response body basically provides multiple ways to produce the response payload.

Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Method Details

    • transform

      Transforms the payload publisher.

      This can be used in an exchange interceptor in order to decorate response data publisher.

      Parameters:
      transformer - a request payload publisher transformer
      Returns:
      the request body
      Throws:
      IllegalArgumentException - if data were already sent to the client
    • empty

      void empty()

      Produces an empty payload.

      If a payload has already been provided this method does nothing.

      A typical usage is:

      
       exchange.response().body().empty();
       
    • raw

      Returns a raw payload producer.

      A typical usage is:

      
       exchange.response().body().raw().stream(
           Flux.just(
               Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hello ", Charsets.DEFAULT)), 
               Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("World!", Charsets.DEFAULT))
           )
       );
       
      Returns:
      a raw payload producer
    • string

      <T extends CharSequence> OutboundData<T> string()

      Returns a string payload producer.

      A typical usage is:

      
       exchange.response().body().string().stream(
           Flux.just(
               Unpooled.unreleasableBuffer("Hello "), 
               Unpooled.unreleasableBuffer("World!")
           )
       );
       
      Type Parameters:
      T - the type of char sequence
      Returns:
      a string payload producer
    • resource

      Returns a resource payload producer.

      A typical usage is:

      
       ResourceService resourceService = ... 
       exchange.response().body().resource().value(resourceService.get("file:/path/to/resource");
       
      Returns:
      a resource payload producer
    • sse

      Returns a server-sent events payload producer as defined by Server-Sent Events.

      A typical usage is:

      
       exchange.response().body().sse().from(
           (events, data) -> Flux.interval(Duration.ofSeconds(1))
               .map(seq -> events.create(event -> event
                       .id(Long.toString(seq))
                       .event("seq")
                       .value(Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Event #" + seq, Charsets.DEFAULT)))
                   )
               )
       );
       
      Returns:
      a server-sent events payload producer
    • sseString

      Returns a server-sent events payload producer as defined by Server-Sent Events.

      A typical usage is:

      
       exchange.response().body().sseString().from(
           (events, data) -> Flux.interval(Duration.ofSeconds(1))
               .map(seq -> events.create(event -> event
                       .id(Long.toString(seq))
                       .event("seq")
                       .value("Event #" + seq, Charsets.DEFAULT))
                   )
               )
       );
       
      Type Parameters:
      T - The type of char sequence
      Returns:
      a server-sent events payload producer