Ktor 1.6.2 Help

Structuring with modules

A Ktor Application consists of a series of one or more modules, each of which can house any kind of functionality.

App Diagram

Module Diagram

A Ktor module is just a user-defined function receiving the Application class that is in charge of configuring the server pipeline, install plugins, registering routes, handling requests, etc.

You have to specify the modules to load when the server starts in the application.conf file.

A simple module function would look like this:

package com.example.myapp fun Application.mymodule() { routing { get("/") { call.respondText("Hello World!") } } }

Of course, you can split the module function in several smaller functions or classes.

Modules are referenced by their fully qualified name: the fully qualified name of the class and the method name, separated by a dot (.).

So for the example, the module's fully qualified name would be:

com.example.myapp.MainKt.mymodule
Last modified: 12 July 2021