Skip to content

Get a description of all registered routes in a RouterFunction [SPR-15711] #20268

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

Closed
spring-projects-issues opened this issue Jun 27, 2017 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 27, 2017

Stéphane Nicoll opened SPR-15711 and commented

Spring Boot has a /mappings endpoint that's quite useful to list the MVC mappings and some interesting characteristics. We build this list by looking at the available AbstractHandlerMethodMapping.

It would be nice if a router that was defined programmatically exposed a similar model.


Affects: 5.0 RC2

Issue Links:

Referenced from: commits 2841ef5

1 votes, 4 watchers

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Due to the hierarchical nature of WebFlux.fn, we cannot simple provide a collection of handler mappings. However, I've added a visitor for router functions, which allows you to create such a description. See poutsma@9f24be7.

For an example visitor, see the ToStringVisitor which is used to create String representation of routes: poutsma@9f24be7#diff-bff3b94ba40e85645a3958709433c53a. For instance, the following router function:

RouterFunction<ServerResponse> routerFunction = nest(path("/person"),
		nest(accept(APPLICATION_JSON),
				route(GET("/{id}"), handler::getPerson)
						.andRoute(method(HttpMethod.GET), handler::allPeople)
		).andRoute(POST("/").and(contentType(APPLICATION_JSON)), handler::savePerson));

the ToStringVisitor returns the string:

/person => {
 Accept: [application/json] => {
  (GET && /{id}) -> org.springframework.demo.webflux.RoutingConfiguration$$Lambda$67/120689887@71c27ee8
  GET -> org.springframework.demo.webflux.RoutingConfiguration$$Lambda$69/250112971@3e7dd664
 }
 ((POST && /) && Content-Type: [application/json]) -> org.springframework.demo.webflux.RoutingConfiguration$$Lambda$70/816798571@5b1ebf56
}

Is the above functionality sufficient for Spring Boot? If so, I will merge it in master.

@spring-projects-issues
Copy link
Collaborator Author

Andy Wilkinson commented

This looks good to me, both for the mappings endpoint and for logging information about routes during startup.

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed as part of 2841ef5

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

2 participants