Skip to content

Add route(RequestPredicate, HandlerFunction) variant to RouterFunctions builder #22701

Closed
@joshlong

Description

@joshlong

Hi

I really like the new functional reactive endpoint style

route()
 .GET("/foo" , getHandlerFunction)
 .POST("/foo", postHandlerFunction)
 .build()

Sometimes however I don't want to use the existing RequestPredicate shortcuts. I'd like to use my own RequestPredicate implementation. In the old style this was easy enough to do. I could say

RequestPredicate rp = r -> Math.random() > .5 ;
return route(rp, myHandlerFunction)
      .andRoute( ...) 

i'm now not quite sure on what the best way to do that in the new style is. this works, but i get the feeling that its re-creating things that dont need to be re-created.


 Consumer<RouterFunctions.Builder> handler() {
  RouterFunction<ServerResponse> handler = r -> Mono.just(r1 -> ok()
	   .syncBody("Hello, " + r1.queryParam("name").orElse("world") + "!"));
		return builder -> builder.add(route().add(handler).build());
	}


RequestPredicate rp = ... ; 

return route()
  .nest(rp, handler())
  .build();

please provide a shortcut for something like:

route()
 .route(RequestPredicate, HandlerFunction<ServerResponse>)
 .build()

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions