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

Support SparkJava's path groups for routes #15

Open
v79 opened this issue Jul 1, 2017 · 2 comments
Open

Support SparkJava's path groups for routes #15

v79 opened this issue Jul 1, 2017 · 2 comments

Comments

@v79
Copy link

v79 commented Jul 1, 2017

It would be useful to support path groups. I've split my code into separate controllers, like so:

class UserController : AbstractController() {
	val users: MutableList<User> = mutableListOf()
	init {
		get("/users") {
                        val model: MutableMap<String,List<User>> = hashMapOf<String,List<User>>()
			model.put("users",users)
			engine.render(ModelAndView(model,"users"))
                }
                post("/users/add-submit") {
			val u:User = User(request.queryParams("name"),request.queryParams("age").toInt())
			users.add(u)
			redirect("/users")
		}
         }
}

Being able to use paths could reduce code duplication:

init {
  path("/users") {
    get("/") {  // e.g. /users/ }
    get("/add") { // e.g. /users/add }
    post("/submit") { // e.g. /users/submit }
  }
}
@perwendel
Copy link
Owner

We'll try to get this into our official release!

@FromSi
Copy link

FromSi commented Dec 17, 2018

We'll try to get this into our official release!

Did you include it in the official release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants