Class WebfluxEntity
java.lang.Object
dmx.fun.spring.webflux.WebfluxEntity
Maps dmx-fun outcomes to a
ResponseEntity for Spring WebFlux annotation
controllers (@RestController), the counterpart of WebfluxFun (which targets
ServerResponse for functional endpoints).
A controller method returns the adapter's Mono<ResponseEntity<…>> directly, so it maps
a domain outcome instead of re-implementing status/body conventions:
@GetMapping("/users/{id}")
Mono<ResponseEntity<User>> user(@PathVariable String id) {
return WebfluxEntity.fromOption(userService.find(id)); // Some -> 200, None/empty -> 404
}
@GetMapping("/orders/{id}")
Mono<ResponseEntity<?>> order(@PathVariable String id) {
return WebfluxEntity.fromResult(orderService.findById(id), // Mono<Result<Order, ApiError>>
error -> ResponseEntity.status(error.status()).body(error.detail()));
}
HTTP conventions mirror WebfluxFun: Ok/Some/Success/Valid
→ 200 with the value as the body; None, an empty source Mono
→ 404; Invalid → 400 with the accumulated errors; Err/Failure
→ your mapper.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<V>> fromOption(reactor.core.publisher.Mono<Option<V>> source) static <V,E> reactor.core.publisher.Mono <org.springframework.http.ResponseEntity<?>> fromResult(reactor.core.publisher.Mono<Result<V, E>> source, Function<? super E, org.springframework.http.ResponseEntity<?>> onError) static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromTry(reactor.core.publisher.Mono<Try<V>> source, Function<? super Throwable, org.springframework.http.ResponseEntity<?>> onFailure) static <E,V> reactor.core.publisher.Mono <org.springframework.http.ResponseEntity<?>> fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source) Maps aValidated:Valid(v)→200withv;Invalid(errors)→400carrying every error (as a list); an empty sourceMono→404.
-
Method Details
-
fromOption
public static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<V>> fromOption(reactor.core.publisher.Mono<Option<V>> source) - Type Parameters:
V- the body type- Parameters:
source- the upstream option- Returns:
- a
Monoemitting the response entity
-
fromResult
public static <V,E> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromResult(reactor.core.publisher.Mono<Result<V, E>> source, Function<? super E, org.springframework.http.ResponseEntity<?>> onError) - Type Parameters:
V- the success body typeE- the error type- Parameters:
source- the upstream resultonError- maps the error to a response entity (status and body of your choosing)- Returns:
- a
Monoemitting the response entity
-
fromTry
public static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromTry(reactor.core.publisher.Mono<Try<V>> source, Function<? super Throwable, org.springframework.http.ResponseEntity<?>> onFailure) - Type Parameters:
V- the success body type- Parameters:
source- the upstream tryonFailure- maps the throwable to a response entity- Returns:
- a
Monoemitting the response entity
-
fromValidated
public static <E,V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source) Maps aValidated:Valid(v)→200withv;Invalid(errors)→400carrying every error (as a list); an empty sourceMono→404.- Type Parameters:
E- the error typeV- the valid body type- Parameters:
source- the upstream validated outcome accumulating errors in aNonEmptyList- Returns:
- a
Monoemitting the response entity
-