How would I got about splitting up my endpoints in...
# ktor
t
How would I got about splitting up my endpoints into separate files? Ideally I want to have this syntax
Copy code
routing {
route("/route", endpoints())
}
or any other way to move all of the posts, deletes etc. out of this file and into something else.
g
Just extract different parts of routing to separate extension functions and call required parts on app initialization
t
I've tried this but I get null as a return to every request.
g
Nothing magic in this code, it's just calling extension functions of DSL on some context, are you sure that your extension functions calls on the same route? Maybe you have some code snippet
t
Copy code
fun Route.catalogueEndpoints(eventBus: EventBus) {
		get("{id}") {
			val response = eventBus.send(
				GetCatalogueByIdQuery(
					catalogueId = call.getParameter("id")
				)
			)

			call.respondToCommand(response)
		}
}
and
Copy code
routing {
		route("/catalogues") {
			catalogueEndpoints(eventBus)
		}
	}
g
And what is
null
in this snippet?
t
call.responToCommand(response) is a function I've implemented that should return a status and a message to the ApplicationCall but instead it doesn't seem to get through
I'm searching for a way to group all of the endpoints of a route together and have them separate from the file in which the route is defined
but so far I've found no solution
Figured it out, finally! 😄
The snippet is correct, my endpoint path was different from the tests so it failed
m
fwiw, i have a working example showing how to do this with Guice here: https://bitbucket.org/marshallpierce/ktor-demo/src/master/