Interface RequestBody


public interface RequestBody

Represents the request payload sent by a client to a server in a client exchange.

The request body basically provides multiple ways to specify the payload.

Since:
1.8
Author:
Jeremy Kuhn
  • Method Details

    • transform

      Transforms the request payload publisher.

      Parameters:
      transformer - a payload publisher transformer
      Returns:
      the request body
    • empty

      void empty()

      Produces an empty payload.

      A typical usage is:

      
       exchange.request().body().ifPresent(body -> body.empty());
       
    • raw

      Returns a raw outbound data producer.

      A typical usage is:

      
       exchange.request().body().ifPresent(body -> body.raw().stream(
           Flux.just(
               Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hello ", Charsets.DEFAULT)), 
               Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("World!", Charsets.DEFAULT))
           )
       ));
       
      Returns:
      a raw outbound data
    • string

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

      Returns a string outbound data producer.

      A typical usage is:

      
       exchange.request().body().ifPresent(body -> body.string().stream(
           Flux.just(
               Unpooled.unreleasableBuffer("Hello "), 
               Unpooled.unreleasableBuffer("World!")
           )
       ));
       
      Type Parameters:
      T - the type of char sequence
      Returns:
      a string outbound data
    • resource

      Returns a resource data producer.

      A typical usage is:

      
       ResourceService resourceService = ... 
       exchange.request().body().ifPresent(body -> body.resource().value(resourceService.get("file:/path/to/resource")));
       
      Returns:
      a resource payload producer
    • urlEncoded

      Returns a URL encoded data producer.

      A typical usage is:

      
       exchange.request().body().ifPresent(body -> body.urlEncoded().from( 
           (factory, output) -> output.stream(Flux.just(
               factory.create("p1", "abc"), 
               factory.create("p2", List.of("a", "b", "c"))
       ))));
       
      Returns:
      a URL encoded data producer
    • multipart

      Returns a Multipart form data producer.

      A typical usage is:

      
       exchange.request().body().ifPresent(body -> body.multipart().from( 
           (factory, output) -> output.stream(Flux.just(
               factory.string(part -> part.name("key").value("value")),
               factory.resource(part -> part
                   .name("myfile")
                   .headers(headers -> headers.contentType("application/json"))
                   .value(new FileResource("sample.json")))
       ))));
       
      Returns:
      a Multipart form data producer