Skip to content

t-kanto/ktor-samples

Β 
Β 

Repository files navigation

Samples for Ktor

A collection of ready-to-use samples for Ktor.

  • "Hello World" application with various deployment scenarios:

  • Other build systems and other samples:

    • maven-netty β€” Maven build for Netty engine embedded application.
    • maven-google-appengine-standard β€” Maven build for Google App Engine Standard (war deployment).
    • proguard β€” Embedded application minimized with ProGuard.
    • multiple-connectors β€” Embedded application listening to several endpoints.
    • sandbox β€” Application including all Ktor artifacts, suitable for Scratches files and quick experiments.
    • simulate-slow-server β€” Application showing how to simulate delay in the whole application creating a simple interceptor.
    • rx β€” Application showing how to use RxJava2.
    • css-dsl β€” Application showing how to combine HTML DSL with CSS DSL.
    • fullstack-mpp β€” Application showing how to combine Ktor serving Kotlin.JS static scripts.
    • filelisting β€” Application showing how to create a file listing for static files.
    • structured-logging β€” Application showing how to use logstash-logback-encoder for structured logging with scoped variables without requiring MDC ThreadStatic.
    • client-multipart β€” Application showing how to do multipart requests with the HttpClient.
    • client-tools β€” Application showing several useful extension methods not included in Ktor itself.
    • sse β€” Shows how to use SSE (Server-Sent Events) using Ktor.
  • Small single-feature samples:

    • async β€” long-running asynchronous computation that happens in a separate thread-pool context.
    • auth β€” using authorization.
    • post β€” form post and multipart file upload.
    • sessions β€” store information that will be kept between requests.
    • custom-feature β€” implementation of a custom feature.
    • html-widget β€” custom html widget.
    • Content Negotiation
    • Dependency Injection
    • locations β€” experimental locations feature.
    • metrics β€” metrics feature.
    • http2-push β€” HTTP/2 with server-side push.
    • ssl β€” SSL support.
    • static content β€” serving static content.
    • testable β€” application writing tests for Ktor applications.
    • websocket (tba)
  • Relatively big sample applications:

    • chat β€” simple chat application using websockets and sessions.
    • httpbin β€” application implementing (large parts of) HttpBin(1) HTTP Request & Response Service.
    • kweet β€” messaging application using freemarker templates and experimental locations feature.
    • youkube β€” video upload/view application using kotlinx.html for rendering and experimental locations feature.

Running samples

Each sample can be run with

./gradlew :<sample-name>:run

Then navigate to http://localhost:8080/ to see the sample home page.

Some samples require additional setup as explained in their readme files.

Cut-and-pasting samples

Each sample is a standalone Gradle project that can be cut-and-pasted to get started with your own project. Cut-and-paste the directory of the corresponding sample together with its build scripts and add gradle.properties from the root that declares Kotlin, Ktor, and other versions. You may remove reference to the versions that this particular sample does not use.

Samples with other build systems (Maven) are fully standalone and can be cut-and-pasted to get started.

Compact directory layout

Samples use compact directory layout whenever possible for ease of navigation:

  • src directory contains sources directly (no src/main/kotlin and package directories).
  • resources directory contains resources.
  • webapp directory contains WEB-INF directory for samples that are deployed as WARs.

About

Sample projects for Ktor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 82.8%
  • HTML 10.4%
  • FreeMarker 2.2%
  • JavaScript 2.1%
  • CSS 1.8%
  • Swift 0.4%
  • Dockerfile 0.3%