GithubHelp home page GithubHelp logo

keke77 / demo-kotlin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pull-vert/demo-kotlin

0.0 0.0 0.0 504 KB

Kotlin web example app for Spring boot 2.X, Webflux and 2 variations : MongoDB and R2DBC. With HTTP/2, RestDoc, Spring Security with JWT and bean validation for received DTOs. Each branch is a new Step. In progress (but waiting for spring-fu releases) : Kofu functional bean registration.

Kotlin 99.79% Vim Snippet 0.21%

demo-kotlin's Introduction

demo-kotlin

This is an example of a Spring boot reactive (Webflux) app in Kotlin, made at first for a live coding and completed since then with new steps. Every step adds new features.

Master contains the most recent finished feature.

Kotlin with Spring annotations (@Service, @Repository...)

Empty files for the demo

MongoDB app is complete (end of live coding) :

  • classic Spring annotations (@Service, @Repository...)
  • Cow entity (data class entity)
  • CowRepository Spring Data Interface
  • CowHandler provide Functional functions (= take ServerRequest as parameter and returns Mono)
  • ApiRoutes provides all Http REST Endpoints of the App
  • DatabaseInitializer initializes the embedded MongoDB with test datas
  • CowRepositoryTest provides JUnit tests for CowRepository
  • ApiTest uses WebTestClient to call real Http REST API
  • Generate a self signed Keystore
keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass secret -dname CN=localhost -validity 360 -keysize 2048
  • stored it in src/main/resources
  • add HTTP/2 and SSL configuration in application.yml
  • change ApiTest (InsecureTrustManagerFactory.INSTANCE) to communicate with self signed server keystore
  • netty-tcnative-boringssl-static dependency is only required for Java 8, since java 9 ALPN is natively supported
  • For production : make a POST and a GET endpoint for let's encrypt HTTP challenge, or use a real well signed Certificate
  • Modify build.gradle to add asciidoc and Spring Restdocs
  • Modify ApiTest to generate doc
  • add index.adoc to expose all API documentation
  • now webservice endpoints consume and return DTOs
  • mapping between POJOs is made by Extension Functions
  • Bean validation with annotations
  • Note : all fields for Request DTO must be nullable to prevent Jackson deserialize error if param is null. Bean validation will take care of returning a nice error to API client
  • Add constraints documentation in Spring Restdocs based on Bean validation annotations

Kotlin with Functional bean registration

inspired by : kofu-reactive-mongodb-sample

  • No more Spring annotations
  • Configuration.kt : declare functional bean registration

Java with Spring annotations (@Service, @Repository...)

Allows to compare Java vs Kotlin code

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.