Git Product home page Git Product logo

kotlin-javalin-realworld-example-app's Introduction

Travis Codacy Badge BCH compliance

RealWorld Example App

Kotlin + Javalin codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API

This codebase was created to demonstrate a fully fledged fullstack application built with Kotlin + Javalin + Koin + Exposed including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Kotlin + Javalin community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

The application was made mainly to demo the functionality of Javalin framework 71.

The application was built with:

  • Kotlin as programming language
  • Javalin as web framework
  • Koin as dependency injection framework
  • Jackson as data bind serialization/deserialization
  • Java-jwt for JWT spec implementation
  • HikariCP as datasource to abstract driver implementation
  • H2 as database
  • Exposed as Sql framework to persistence layer
  • slugify

Tests:

Structure

  + config/
      All app setups. Javalin, Koin and Database
  + domain/
    + repository/
        Persistence layer and tables definition
    + service/
        Logic layer and transformation data
  + ext/
      Extension of String for email validation
  + utils/
      Jwt and Encrypt classes
  + web/
    + controllers
        Classes and methods to mapping actions of routes
    Router definition to features and exceptions
  - App.kt <- The main class

Database

It uses a H2 in memory database (for now), can be changed easily in the koin.properties for any other database. You'll need to add the correct dependency for the needed Driver in build.gradle.

Getting started

You need just JVM installed.

The server is configured to start on 7000 with api context, but you can change in koin.properties.

Build:

./gradlew clean build

Start the server:

./gradlew run

In the project have the spec-api with the README and collections to execute backend tests specs realworld.

You can access the h2-console at console.

Execute tests and start the server:

./gradlew run & APIURL=http://localhost:7000/api ./spec-api/run-api-tests.sh

Help

Please fork and PR to improve the code.

kotlin-javalin-realworld-example-app's People

Contributors

codacy-badger avatar davidpodhola avatar dependabot[bot] avatar podholadavid avatar rudge avatar vn7n24fzkq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kotlin-javalin-realworld-example-app's Issues

Want add swagger-docs.

Hi @Rudge ,I want to write some annotation for auto generate swagger-ui page as a pull request but this need upgrade javalin version to lastest.
What do you think?

Resource not found error

I tried running this app, but I'm getting a NotFoundResponse error. The test suite passed without any errors.

H2 Database Console

Hi, I would like to know how to enable the h2 db console?
In spring projects, We just have to put these properties:
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

How about javalin project?
Thanks in advanced.

ps.: I dont know if it is the right place to send this question.

Runtime JAR files in the classpath should have the same version

Hi,

I would like to see this realworld example, but I cannot get it working.
I have tried to build it using gradlew clean build
There is a warning:

> Task :compileKotlin
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.61/e91d61b7cfd9a45566b580fef18bbd5c32d505b5/kotlin-stdlib-jdk8-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.61/70dffc5f8ac5ea7c34f30deac5b9d8b1d48af066/kotlin-stdlib-jdk7-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.71/7512db3b3182753bd2e48ce8d345abbadc40fe6b/kotlin-reflect-1.2.71.jar (version 1.2)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.61/4702105e97f7396ae41b113fdbdc180ec1eb1e36/kotlin-stdlib-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.61/65abb71d5afb850b68be03987b08e2c864ca3110/kotlin-stdlib-common-1.3.61.jar (version 1.3)
w: Consider providing an explicit dependency on kotlin-reflect 1.3 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

> Task :compileTestKotlin
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.61/e91d61b7cfd9a45566b580fef18bbd5c32d505b5/kotlin-stdlib-jdk8-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.61/70dffc5f8ac5ea7c34f30deac5b9d8b1d48af066/kotlin-stdlib-jdk7-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.71/7512db3b3182753bd2e48ce8d345abbadc40fe6b/kotlin-reflect-1.2.71.jar (version 1.2)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.61/4702105e97f7396ae41b113fdbdc180ec1eb1e36/kotlin-stdlib-1.3.61.jar (version 1.3)
    C:/Users/olaf.XSODOMAIN/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.61/65abb71d5afb850b68be03987b08e2c864ca3110/kotlin-stdlib-common-1.3.61.jar (version 1.3)
w: Consider providing an explicit dependency on kotlin-reflect 1.3 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath

I run the app using gradlew run
Then it logs:

> Task :run
2019-12-05 11:10:19:319 (KOIN)::[i] [PrintLogger] display debug = false
2019-12-05 11:10:19:335 (KOIN)::[i] [properties] load koin.properties
2019-12-05 11:10:19:335 (KOIN)::[i] [properties] load environment properties
2019-12-05 11:10:19:350 (KOIN)::[i] [definition] declare Single [name='AppConfig',class='io.realworld.app.config.AppConfig']
2019-12-05 11:10:19:350 (KOIN)::[i] [definition] declare Single [name='JwtProvider',class='io.realworld.app.utils.JwtProvider']
2019-12-05 11:10:19:350 (KOIN)::[i] [definition] declare Single [name='AuthConfig',class='io.realworld.app.config.AuthConfig']
2019-12-05 11:10:19:350 (KOIN)::[i] [definition] declare Single [name='DataSource',class='javax.sql.DataSource']
2019-12-05 11:10:19:350 (KOIN)::[i] [definition] declare Single [name='Router',class='io.realworld.app.web.Router']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='UserController',class='io.realworld.app.web.controllers.UserController']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='UserService',class='io.realworld.app.domain.service.UserService']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='UserRepository',class='io.realworld.app.domain.repository.UserRepository']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='ArticleController',class='io.realworld.app.web.controllers.ArticleController']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='ArticleService',class='io.realworld.app.domain.service.ArticleService']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='ArticleRepository',class='io.realworld.app.domain.repository.ArticleRepository']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='ProfileController',class='io.realworld.app.web.controllers.ProfileController']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='CommentController',class='io.realworld.app.web.controllers.CommentController']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='CommentService',class='io.realworld.app.domain.service.CommentService']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='CommentRepository',class='io.realworld.app.domain.repository.CommentRepository']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='TagController',class='io.realworld.app.web.controllers.TagController']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='TagService',class='io.realworld.app.domain.service.TagService']
2019-12-05 11:10:19:366 (KOIN)::[i] [definition] declare Single [name='TagRepository',class='io.realworld.app.domain.repository.TagRepository']
2019-12-05 11:10:19:366 (KOIN)::[i] [modules] loaded 18 definitions
2019-12-05 11:10:19:366 (KOIN)::[i] [modules] loaded in 15.789 ms
2019-12-05 11:10:19:366 (KOIN)::[i] [Koin] started in 42.1029 ms
2019-12-05 11:10:19:585 (KOIN)::[i] +-- 'io.realworld.app.config.AuthConfig'
2019-12-05 11:10:19:585 (KOIN)::[i] |	+-- 'io.realworld.app.utils.JwtProvider'
2019-12-05 11:10:19:585 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:19:585 (KOIN)::[i] \-- (*) Created
2019-12-05 11:10:19:585 (KOIN)::[i] +-- 'io.realworld.app.web.Router'
2019-12-05 11:10:19:585 (KOIN)::[i] |	+-- 'io.realworld.app.web.controllers.UserController'
2019-12-05 11:10:19:585 (KOIN)::[i] |	|	+-- 'io.realworld.app.domain.service.UserService'
2019-12-05 11:10:19:585 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.utils.JwtProvider'
2019-12-05 11:10:19:585 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.domain.repository.UserRepository'
2019-12-05 11:10:19:585 (KOIN)::[i] |	|	|	|	+-- 'javax.sql.DataSource'
2019-12-05 11:10:19:694 (KOIN)::[i] |	|	|	|	\-- (*) Created
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	|	\-- (*) Created
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	\-- (*) Created
2019-12-05 11:10:20:178 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:20:178 (KOIN)::[i] |	+-- 'io.realworld.app.web.controllers.ProfileController'
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	+-- 'io.realworld.app.domain.service.UserService'
2019-12-05 11:10:20:178 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:20:178 (KOIN)::[i] |	+-- 'io.realworld.app.web.controllers.ArticleController'
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	+-- 'io.realworld.app.domain.service.ArticleService'
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.domain.repository.ArticleRepository'
2019-12-05 11:10:20:178 (KOIN)::[i] |	|	|	|	+-- 'javax.sql.DataSource'
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	|	\-- (*) Created
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.domain.repository.UserRepository'
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	\-- (*) Created
2019-12-05 11:10:20:194 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:20:194 (KOIN)::[i] |	+-- 'io.realworld.app.web.controllers.CommentController'
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	+-- 'io.realworld.app.domain.service.CommentService'
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.domain.repository.CommentRepository'
2019-12-05 11:10:20:194 (KOIN)::[i] |	|	|	|	+-- 'javax.sql.DataSource'
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	|	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] |	+-- 'io.realworld.app.web.controllers.TagController'
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	+-- 'io.realworld.app.domain.service.TagService'
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	|	+-- 'io.realworld.app.domain.repository.TagRepository'
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	|	|	+-- 'javax.sql.DataSource'
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	|	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] |	|	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] |	\-- (*) Created
2019-12-05 11:10:20:209 (KOIN)::[i] \-- (*) Created

Then I browsed to http://localhost:7000/api/
As result:
{"errors":{"body":["Resource can't be found to fulfill the request."]}}

No app is showing, what can be wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.