Skip to content

Make path pattern optional in router functions #25752

@helmbold

Description

@helmbold

Affects: 5.2

If WebMvc.fn is used with nested routes, it is not always necessary to specify the path pattern for every registered handler.

accept(APPLICATION_JSON).nest {
  path("/{listId}").nest {
    GET("", listHandler::findById)
    PUT("", listHandler::update)
    DELETE("", listHandler::delete)
  }
  path("/{listId}/{taskId}").nest {
    GET("", taskHandler::findById)
    DELETE("", taskHandler::delete)
  }
}

The path pattern is only specified at the surrounding path element. Below this element all handlers are related to the given path, like /{listId}/.

A path with verbs (GET, PUT, ...) would pretty much reflect the concept of a REST "resource".

I suggest the following syntax:

accept(APPLICATION_JSON).nest {
  path("/{listId}").nest {
    GET(listHandler::findById)
    PUT(listHandler::update)
    DELETE(listHandler::delete)
  }
}

Since all handler registrations share the same base path, there is no need to specify it on each element.

It should be possible to use predicates without a path, too.

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