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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
RequestBody.Multipart<A extends Part.Factory,
B extends Part<?>> A Multipart form data producer.static interface
A resource data producer.static interface
RequestBody.UrlEncoded<A extends Parameter.Factory>
A URL encoded data producer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
empty()
Produces an empty payload.Returns a Multipart form data producer.raw()
Returns a raw outbound data producer.resource()
Returns a resource data producer.<T extends CharSequence>
OutboundData<T> string()
Returns a string outbound data producer.Transforms the request payload publisher.Returns a URL encoded data producer.
-
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
OutboundData<ByteBuf> 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
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
RequestBody.Resource 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
RequestBody.UrlEncoded<Parameter.Factory> 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
RequestBody.Multipart<Part.Factory,Part<?>> 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
-