Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joshlong opened this issue Mar 28, 2019 · 2 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@joshlong
Copy link
Member

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()
@joshlong joshlong changed the title please support an easy way to contribute a RequestPredicate + HandlerFunction<ServerResponse> pair with the fn reactive route()....build() style please support a RequestPredicate + HandlerFunction<ServerResponse> pair with the new functional reactive style Mar 28, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 28, 2019
@poutsma poutsma self-assigned this Mar 28, 2019
@poutsma
Copy link
Contributor

poutsma commented Mar 28, 2019

There is add, which you can combine with the "old-style" route, like so:

RequestPredicate rp = r -> Math.random() > .5 ;
route()
 .GET("/foo" , getHandlerFunction)
 .POST("/foo", postHandlerFunction)
 .add(route(rp, myHandlerFunction))
 .build()

Is this good enough? Or do you still prefer to have a separate route.route(RequestPredicate, HandlerFunction) method added to the builder?

@joshlong
Copy link
Member Author

joshlong commented Apr 1, 2019

A separate route/add or whatever you prefer that takes RequestaPredicare / HandlerFunction Would be preferable as it’s not clear to me, at least, that you’d need to call route(...) to build a thing that add could accept. This is probably because everything is a lambda and I don’t spend a lot of time looking at actual types. Either way, would be nice to have a method that looks like route(..) in the older DSL. Thanks in advance

@poutsma poutsma added this to the 5.2 M2 milestone Apr 4, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 10, 2019
@poutsma poutsma changed the title please support a RequestPredicate + HandlerFunction<ServerResponse> pair with the new functional reactive style Add route(RequestPredicate, HandlerFunction) variant to RouterFunctions builder May 7, 2019
@poutsma poutsma closed this as completed in 59f6044 May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants