Escribe para buscar…

Server

Esta página todavía no se ha traducido — se muestra en su idioma original:English

Introduction

Ktor is built on Coroutine and lets you use only what you need while structuring your application your way. You can also extend Ktor with your own plugins easily.

Project setup

Generate a “Ktor server application” with Amper.

Two files are created under src: Application.kt and Routing.kt.

Run the project:

Open http://localhost:8080 to confirm it’s running.

You should see “Hello World!”:

Server

EngineMain starts a server with the selected engine and loads application modules from the external configuration file application.yaml, typically located in the resource directory.

kotlin
src/Application.kt
import io.ktor.server.application.*

fun main(args: Array<String>) {
    io.ktor.server.netty.EngineMain.main(args)
}

fun Application.module() {
    configureRouting()
}

In addition to specifying which modules to load, the configuration file can include various server parameters such as the port, host, and SSL settings.

In this link you can find the full list of parameters: Server Configuration

Amper

To enable Ktor support, you add the following to the module.yaml file:

yaml
settings:
  ktor: enabled

Setting ktor: enabled performs the following actions:

  • Applies Ktor BOM
  • Contributes Ktor-related entries to a built-in library catalog
  • Adds the io.ktor.development=true system property when running the app with amper run

You can also customize the version of the Ktor libraries using the full form of the configuration:

yaml
settings:
  ktor:
    enabled: true
    version: 3.3.2

Autoreload

Restarting a server during development can be slow. Ktor supports auto-reload to speed up the feedback loop:

yaml
resources/application.yaml
ktor:
    development: true

Estás leyendo una vista previa.

Inicia sesión con Google para leer la página completa. Sigue el itinerario de aprendizaje — cada página se desbloquea cuando has leído las que la preceden. El alumnado y el profesorado leen las páginas de su curso sin límite.

Iniciar sesión