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

Possible to group request handlers into controllers? #16

Closed
pehagg opened this issue Jul 7, 2017 · 2 comments
Closed

Possible to group request handlers into controllers? #16

pehagg opened this issue Jul 7, 2017 · 2 comments

Comments

@pehagg
Copy link

pehagg commented Jul 7, 2017

Question/Feature request: I tend to write apps where the code is grouped by feature/package (opposed to group-by-layer) in order to achieve cleaner code, especially when it comes to larger codebases. I'm a newbie to Kotlin and haven't figured a way how to group routes into controllers using spark-kotlin, sparkjava supports this pattern. Is this possible, and if so how? In case it isn't, would it be possible to add support for it to spark-kotlin?

@v79
Copy link

v79 commented Jul 7, 2017

@pehagg It is possible; each controller class defines its own routes in the constructor init { } block. The main server class just needs to initialise each controller on statup. I've got a toy example working at https://github.com/v79/kotlin-spark-routes . Adding spark's paths would help with this ( #15 ). I've tried calling Spark.path("/users/") {... } but it breaks staticFiles() for me.

@pehagg
Copy link
Author

pehagg commented Jul 8, 2017

Thanks @v79, this was exactly what I was looking for! You example was of great help.

I'll close the issue as #15 is reported separately.

@pehagg pehagg closed this as completed Jul 8, 2017
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

2 participants