A collection of ready-to-use samples for Ktor.
-
"Hello World" application with various deployment scenarios:
- netty β Netty engine application.
- netty-embedded β Netty engine embedded application.
- jetty β Jetty engine application.
- jetty-embedded β Jetty engine embedded application.
- jetty-war β Jetty application server WAR deployment.
- tomcat-war β Tomcat application server WAR deployment.
- google-appengine-standard β Google App Engine Standard (war deployment).
-
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
- gson β using Gson.
- jackson β using Jackson.
- json-client β HTTP client with JSON support feature.
- 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.
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.
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.
Samples use compact directory layout whenever possible for ease of navigation:
src
directory contains sources directly (nosrc/main/kotlin
and package directories).resources
directory contains resources.webapp
directory containsWEB-INF
directory for samples that are deployed as WARs.