This repository contains a Ktor-based application with various routes and their corresponding tests. The application manages counters, providing endpoints to create, read, update, and delete counters. Testing is implemented using Kotlin's kotest
and ktor-server-tests
libraries.
- src/main/kotlin: Contains the main application code, including route definitions and services.
- src/test/kotlin: Contains the test cases for the application routes.
- build.gradle.kts: The Gradle build script for managing dependencies and build tasks.
Also, there's swagger available at:
http://0.0.0.0:8080/swagger
- Description: Retrieves the value of a specified counter.
- Query Parameter:
counter
(the name of the counter to read) - Responses:
200 OK
: When the counter exists. Response body includes counter's details.404 Not Found
: When the counter does not exist.
- Description: Creates a new counter with the specified value.
- Request Body: JSON object containing
name
andcounter
values, which is being validated for blank value and for negative value. - Responses:
201 Created
: When the counter is successfully created. Response body includes the created counter's details.400 Bad Request
: When request validation failed.
- Description: Increments the value of a specified counter.
- Query Parameter:
counter
(the name of the counter to increment) - Responses:
200 OK
: When the counter exists and is incremented. Response body includes the new value.422 UnprocessableEntity
: When the counter does not exist.
- Description: Deletes the specified counter.
- Query Parameter:
counter
(the name of the counter to delete) - Responses:
204 No Content
: When the counter is successfully deleted.
- Description: Retrieves a list of all counters.
- Responses:
200 OK
: Returns a list of all counters in JSON format.
To get started with this project, follow these steps:
-
Clone the repository:
git clone https://github.com/vendelieu/ktor-sample.git
-
Navigate to the project directory:
cd ktor-sample
-
Build the project:
./gradlew build
-
Run the application:
./gradlew run
To run the tests, use the following command:
./gradlew test
- Ktor: Web framework for building the application.
- Kotlin serialization: Kotlin Serde framework.
- Kotest: Testing framework for Kotlin.
- H2: In-memory database for testing purposes.
- Exposed: Database access library for Kotlin.