Skip to content

Hades is backend written in Kotlin using Ktor. It's main purpose is to demonstrate basic CRUD operations on different types of data sources.

License

Notifications You must be signed in to change notification settings

karic-kenan/Hades

Repository files navigation

Hades

Hades is backend written in Kotlin using Ktor. It's purpose is to demonstrate basic usages of CRUD operations on InMemory database / H2 database (in memory) / PostgreSQL database. If you need GraphQL version of this (simplifed of course for learning purposes), visit: HadesQL

Install

Clone the project and run it. Simple as that.

By default it uses H2 database while working with Exposed to store data, but if you prefer to use InMemory one then in framework package, under di, use single<MainRepository> { InMemoryRepository() } instead of single<MainRepository> { DefaultMainRepository() } in RepositoriesModule.

All endpoints aside from authentication will contain API version: "http://localhost:8080/api/v1/..."

Built with

  • Kotlin - Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference.
  • Ktor - Ktor is an asynchronous framework for creating microservices, web applications, etc.
  • Coroutines - For asynchronous and more..
  • Dependency Injection -
    • Koin - A pragmatic lightweight dependency injection framework for Kotlin developers.
  • Exposed - Exposed is a lightweight SQL library on top of JDBC driver for Kotlin language.
  • Gson - Content negotiation which provides Gson converter for handling JSON data.
  • Hikari - HikariCP is a "zero-overhead" production ready JDBC connection pool.
  • PostgreSQL - PostgreSQL is an advanced object-relational database management syste.
  • Locations - Type-safe routes.
  • Also contains JWT authentication.

Database

Project has three data sources:

  1. InMemory (turned off)
  2. H2 (also in memory but uses actual data) (default)
  3. PostgreSQL

In case you want to switch from H2 to PostgreSQL you have two options (edit DatabaseFactory.kt file):

  1. Use regular connection to PostgreSQL; Turn off H2 (comment it out) and turn on PostgreSQL, that is
Database.connect(
    url = "jdbc:postgresql://database:5432/thoughtsDb",
    driver = "org.postgresql.Driver",
    user = "username",
    password = "secret"
)
  1. Setup via Hikari, with connection pooling; turn on following:
val config = HikariConfig().apply {
    jdbcUrl = "jdbc:postgresql://database:5432/thoughtsDb"
    driverClassName = "org.postgresql.Driver"
    username = "username"
    password = "secret"
    maximumPoolSize = 10
}

val dataSource = HikariDataSource(config)
Database.connect(dataSource)

Running the project

In case of H2/InMemory data source (default is H2 already), running the project as is should be fine. Simply use one of the two and run it. In case of PostgreSQL, there's bit of a setup although major work is in place already:

  1. Install PostgreSQL
  2. Install Docker. Make sure after you install Docker, that it's running as expected.
  3. Setup docker-compose.yml file according to your specification (or keep as is for default):
  • Container 1#app with name, port and database dependency
  • Container 2#database with image, environment, port
  • Note: Environment contains database name, username and password. Keep them secret. They're here and alive for learning purposes.
  1. In terminal, navigate to your project and run command: docker-compose up --build (in case you are re-running the project, simply omit the --build)
  2. Then in new tab in terminal, in root of your workspace, run command: docker exec -t -i thoughts-app bash (thoughts-app is name of our container which will be created)
  • Once that's done, you should be in bash
  • In there run command: ./gradlew -t installDist
  • Wait until it's done (you'll see line: "Waiting for changes...")
  1. Test via Postman

If all done correctly, you'll should see two containers created in docker, as well as your terminal windows being updated as you work with postman to test the data.

Contribute

If you want to contribute to this repository, you're always welcome!

Contact

If you need any help, feel free to contact me: kenan.karic@outlook.com.

License

License

About

Hades is backend written in Kotlin using Ktor. It's main purpose is to demonstrate basic CRUD operations on different types of data sources.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published