Skip to content

selimatasoy/kotlin-ktor-rest-api

Repository files navigation

kotlin-ktor-rest-api

A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations. Focused on Software Architecture, SOLID Principles, dependency injection, testable code and feature based development.

  • Ktor Framework
  • Kotlin
  • Dependency Injection -> Koin
  • Authorization -> JWT
  • Database -> PostgreSQL
  • ORM SQL Framework -> Exposed
  • Ktor Client -> For External API calls
  • Build Tool -> Gradle
  • Server -> Tomcat
  • Docker support for containerization
  • POSTMAN Collection for testing API
  • Gradle 7, JDK (Amazon Coretto 11)

Architecture

github (6)

Database Credentials (Please add your PostgreSQL credentials here to connect to your database)

resources/application.conf

    database {
        exampleDatabaseUrl="jdbc:postgresql://localhost:5432/$YOUR_DB_NAME"
        exampleDatabaseDriver="org.postgresql.Driver"
        exampleDatabaseUser="$YOUR_USERNAME"
        exampleDatabasePassword="$YOUR_PASSWORD"
    }

Features

- Health Check

GET /public-api/v1/healthCheck
  Just returns a simple object

- Authentication

POST /public-api/v1/authentication/createUser
  Registers a user to the db
POST /public-api/v1/authentication/login
  Returns a jwt token if success
GET /api/v1/authentication/userInfo (Needs Authorization token from login as Authorization header : "Bearer $token")
  Returns the user information

- Star Wars

GET /api/v1/star-wars/movie (Needs Authorization token from login as Authorization header : "Bearer $token")
  An External API call example. Returns a movie information from an external api

About

A Modern Kotlin-Ktor RESTful API example. Connects to a PostgreSQL database and uses Exposed framework for database operations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published