Ktor allows you to use modules to structure your application by defining a specific set of routes inside a specific module. A module is an extension function of the Application class. In the example below, the
module1 extension function defines a module that accepts GET requests made to the
/module1 URL path.
Loading modules in your application depends on the way used to create a server: in code using the
embeddedServer function or by using the
application.conf configuration file.
embeddedServer function accepts a module implicitly as a lambda argument. You can see the example in the Configuration in code section. You can also extract application logic into separate modules and call these module functions inside the
You can find the full example here: embedded-server-modules.
If you use the
application.conf file to configure a server, you need to specify modules to load using the
Suppose you have three modules defined in two packages: two modules in the
com.example package and one in the
To reference these modules in a configuration file, you need to provide their fully qualified names, separated by a comma. A fully qualified module name includes a fully qualified name of the class and an extension function name.
You can find the full example here: engine-main-modules.