SlideShare a Scribd company logo
Kotlin Backend
Rest & GraphQL
About Me
● Blog
○ https://animus.design
● GitLab
○ https://gitlab.com/AnimusDesign
● Job: Tech Lead @ Equinox
● Personal Projects
○ Music Recommendation System
○ Kotlin Examples
○ New Web Framework in Kotlin
○ Content Creation Service
Over ten years of experience. With a focus on
functional reactive full stack development. Utilizing
Kotlin to ease delivering of the domain to the client.
Early adopter of multi-platform to share code across
multiple targets.
What is GraphQL
● GraphQL is a newish API format developed by FaceBook for React. First released in 2015
○ Primarily used by Javascript Frameworks
● It is strongly typed, with a schema. Allowing for autocompletion, and is self documenting.
● You specify what data you wish to receive. In that vein you can chain multiple queries, without hitting
multiple endpoints.
○ Think of it as akin to sql, with functions instead of a language, but you still specify the returns.
● Advanced
○ Can whitelist queries run in production, limiting ad hoc queries.
○ Can build fragments that act as building blocks inside queries.
● Hacker News Discussion on Switching to GraphQL
Simple Query
Complex Query
GraphQL Additions
● GraphQL is a specification, additional libraries/frameworks expand its capabilities.
○ Much like an api gateway for REST, joining microservices.
● This is required because the structure of the data is put on the client instead of the server.
● Relay & Relay Modern from FaceBook, allow data binding to components, caching, etc.
● Apollo acts as a GraphQL API GateWay, with monitoring, alerting, and other features.
○ Client supports caching, binding, and managing local state of the application.
● Important
○ Support outside of JavaScript is weak. As an example JVM doesn’t support caching in Apollo, but
supports performance tracing.
● I will be focusing on Apollo
GraphQL Schema Stitching
● Schema stitching combines several GraphQL end points into one.
● Equivalent to an api gateway.
● When making a query, it will route the request to the proper service.
Why is the Framework Important?
● Isomorphic rendering, or server side rendering with GraphQL
● Caching, to limit hitting the primary data source repeatedly.
● How the javascript/Client interacts with the data layer.
● Whether the build process verifies the requested fields are in the schema.
● Performance monitoring, and trace monitoring.
● Schema stitching, or combining multiple graphql services together.
In short your framework choice will largely dictate your backend
language.
Why use GraphQL
● You’re using a javascript web/mobile framework.
● With Apollo client for web and mobile.
● Limits the data requested.
● Can whitelist queries, verifying what is queried in production.
● Less data requested, means less transfer.
○ Customize the data you retrieve from the data source.
● Reduce number of api calls.
● Strongly typed response.
● No need to maintain / generate swagger documentation.
Why Apollo?
● Polyglot support Swift (iOS), Kotlin (Android), JavaScript (vue, react, angular)
clients.
● Wide range of backend server support
○ With varying levels of support..
■ Tracing is supported in Java and other languages, see here for latest
supported languages.
○ Caching javascript only at this time.
● Integration with pager-duty and data dog, easing monitoring.
● Shiny dashboard with pretty lines.
● Better community integration, things like React router for isomorphic
rendering.
● Professional support
Backend MakeUp
● API
○ Jooby
■ HTTP Routing Library
○ Java-GraphQL
■ FrameWork for GraphQL
○ Graphql-spqr
■ Java 8+ Bindings easing definition, but not targeted towards
kotlin.
○ Jooq
■ Database layer that acts as a thin layer for operations.
○ Hikari CP
■ Connection pooling for the database.
● Apollo
○ GraphQL GateWay Server
○ Performance Monitoring
● Graphite + Grafana Monitoring
Project Structure
● Base Structure we will be working with.
● api
○ Is the backend GraphQL and Rest layer.
● database
○ The database interaction library.
● Web
○ A react frontend
● Anything gradle is build related.
DataBase
● Auto generated java classes via jooq.
● No hand writing or mapping to database.
● Generated via a gradle build file.
● Utilizes environment variables to integrate
with your pipeline.
● Looks strikingly like SQL.
Data Model
● Name Basic - Provides information on actors, writers, crews, etc.
● Title Basic - Common information on a title can be a movie or tv episode.
● Title AKA - Title also known as a table of other title names, not used.
● Title Episode - Maps a parent title (TV Show), to seasons, episode numbers, and episode
ids.
● Title Crew - Takes a title id and provides a list of directors and writers.
Pulled from IMBD sample data set. Small sample set of movies, tv shows, writers, directors, and
actors.
https://www.imdb.com/interfaces/
Jooby: HTTP API GraphQl & Rest
● GraphQL requires a single POST or GET endpoint
● Supports multi versioned REST endpoints
● Swagger and RAML generation for Rest
● Metrics, supporting graphite, data dog and more.
● Docker support
● A number of other modules
● Running on Netty an asynchronous event server
○ Can run on other servers.
● Support for hot reloading, i.e. automatic recompilation.
There are a Plethora of HTTP Services
Choose what works for you!
● Vertx
● DropWizard
● Javalin
● Spark
● Ktor
● I’m sure I’m forgetting something.
Jooby Making End Points
● Closures, lambda functions included in a type safe DSL builder.
● Supports MVC class based method (My preference)
Jooby Closure REST EndPoint
● A type safe builder for your end points in the run section for Jooby.
● Supports arguments and parameters.
● Each http verb is a seperate function
Class MVC Rest EndPoint
- Each Class is a
path
- Annotated with
the HTTP verb
- Can annotate
with sub path
- Automatic
conversion to
json
Single GraphQL EndPoint
- Data classes for response and post
body.
- Read the post body.
- Submit to the schema executor
- Return response.
GraphQL Java
● Strong Community, very active development.
● Support for Apollo (minus caching) and Relay, plus more.
● A number of additions to ease development.
○ https://github.com/graphql-java/awesome-graphql-java
● Can design schema first or classes first.
● Automatic integration with spring.
Limitations of GraphQL Java
● Kotlin is not a first class citizen.
● Builders, that feel a bit heavy in comparison to Kotlin Syntax.
● Documentation is a bit scarce.
● Wiring type definitions, to query resolvers is verbose.
● Doesn’t feel like idiomatic Kotlin
○ There is one Wrapper in Kotlin, but it is not overly active
● Enter GraphQL SPQR.
○ An annotation library that makes adding types and queries very simple.
○ The downside is it doesn’t support Kotlin Data Classes
■ Need to fall back to java in some instances.
■ May encounter esoteric bugs with annotations in Kotlin.
GraphQL Object Definition
● Basic Java POJO
● Annotations for the Getters
Or This Works
● Class constructor with
annotations.
● Common class so can be used
across platforms.
● This is the JVM implementation.
GraphQL Service
Generating the Schema
● Instantiate the Pet Service a singleton
● Instantiate the schema, passing any singletons you develop.
Demo Time
● Data store is using sample data from
IMDB
● REST + GraphQL Endpoints
○ Hot Reloading
● Apollo Engine Integration
○ GraphQL Query Tracing
● Grafana showing Jooby metrics
● Docker build
● Maybe a kotlin + react fetching from
the API.
Closing Thoughts
VertX
If you’re looking for a highly concurrent distributed backend layer. Look at VertX.
● Works with an event loop, and worker pools.
○ Passing information through a message bus.
■ Which can be centralized
■ And accessed from a number of languages.
● Can start with just http endpoints and add more later.
● Built in clustering and service discovery.
● First class Kotlin support.
● Polyglot (Java, Kotlin, Groovy, Scala, Javascript, Ruby)
● HTTP end points, as well as custom TCP/UDP services.
● Akin to an actor model.
● Great GraphQL support.
Changing your data store
● Neo4j (graph database has built in graphql
support).
● In built use of GraphQL Java and Apollo
● But you have to change your data store…
● Called the Grand Stack
Could we create new annotations?
Questions ?

More Related Content

PDF
Implementing GraphQL API in Elixir – Victor Deryagin
PDF
A Tour of the Modern Java Platform
PDF
ReactiveX
PDF
ReactiveX-SEA
PDF
Demo on JavaFX
PDF
Modern APIs with GraphQL
PDF
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
PDF
Introduction to GraphQL
Implementing GraphQL API in Elixir – Victor Deryagin
A Tour of the Modern Java Platform
ReactiveX
ReactiveX-SEA
Demo on JavaFX
Modern APIs with GraphQL
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
Introduction to GraphQL

What's hot (20)

PDF
Introduction to DevOps and the Practical Use Cases at Credit OK
PDF
GraphQL & Relay
PDF
GraphQL + relay
PDF
Apache Beam @ GCPUG.TW Flink.TW 20161006
PPTX
Introduction to GraphQL
PPTX
GraphQL Introduction
PDF
The Apollo and GraphQL Stack
PDF
GraphQL ♥︎ GraphDB
PDF
Adding GraphQL to your existing architecture
PPTX
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
PDF
REST vs GraphQL
PDF
Improving Mobile Payments With Real time Spark
PPTX
Introduction to Ruby Native Extensions and Foreign Function Interface
PDF
GraphQL (Graphene-Django)
PDF
GraphQL in an Age of REST
PPTX
Python Streaming Pipelines with Beam on Flink
PDF
GraphQL across the stack: How everything fits together
PDF
Balkan - data eng meetup - data fusion
PDF
Introduction to Modern DevOps Technologies
PDF
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Introduction to DevOps and the Practical Use Cases at Credit OK
GraphQL & Relay
GraphQL + relay
Apache Beam @ GCPUG.TW Flink.TW 20161006
Introduction to GraphQL
GraphQL Introduction
The Apollo and GraphQL Stack
GraphQL ♥︎ GraphDB
Adding GraphQL to your existing architecture
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
REST vs GraphQL
Improving Mobile Payments With Real time Spark
Introduction to Ruby Native Extensions and Foreign Function Interface
GraphQL (Graphene-Django)
GraphQL in an Age of REST
Python Streaming Pipelines with Beam on Flink
GraphQL across the stack: How everything fits together
Balkan - data eng meetup - data fusion
Introduction to Modern DevOps Technologies
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Ad

Similar to Kotlin REST & GraphQL API (20)

PPTX
GraphQL-ify your APIs - Devoxx UK 2021
PDF
GraphQL Bangkok meetup 5.0
PPTX
GraphQL-ify your APIs
PDF
GraphQL-ify your APIs
PDF
GraphQL for Native Apps
PPTX
GraphQL_devoxx_2023.pptx
PDF
GraphQL-ify your API - JFall 2022
PDF
Marco Liberati - Graph analytics
PPTX
GraphQL API Crafts presentation
PDF
GraphQL- Presentation
PDF
PPTX
The API Journey: from REST to GraphQL
PPTX
GraphQL - The new "Lingua Franca" for API-Development
PDF
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
PDF
Building Fullstack Serverless GraphQL APIs In The Cloud
PDF
GraphQL: Enabling a new generation of API developer tools
PPTX
GraphQL Introduction with Spring Boot
PDF
Introduction to GraphQL for beginners
PDF
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
PPTX
Apollo 4 Kotlin made me Graphql and I learned how to use it
GraphQL-ify your APIs - Devoxx UK 2021
GraphQL Bangkok meetup 5.0
GraphQL-ify your APIs
GraphQL-ify your APIs
GraphQL for Native Apps
GraphQL_devoxx_2023.pptx
GraphQL-ify your API - JFall 2022
Marco Liberati - Graph analytics
GraphQL API Crafts presentation
GraphQL- Presentation
The API Journey: from REST to GraphQL
GraphQL - The new "Lingua Franca" for API-Development
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
Building Fullstack Serverless GraphQL APIs In The Cloud
GraphQL: Enabling a new generation of API developer tools
GraphQL Introduction with Spring Boot
Introduction to GraphQL for beginners
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
Apollo 4 Kotlin made me Graphql and I learned how to use it
Ad

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Nekopoi APK 2025 free lastest update
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
ai tools demonstartion for schools and inter college
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo Companies in India – Driving Business Transformation.pdf
Odoo POS Development Services by CandidRoot Solutions
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Introduction to Artificial Intelligence
wealthsignaloriginal-com-DS-text-... (1).pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
Nekopoi APK 2025 free lastest update
Reimagine Home Health with the Power of Agentic AI​
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Operating system designcfffgfgggggggvggggggggg
How to Migrate SBCGlobal Email to Yahoo Easily
How Creative Agencies Leverage Project Management Software.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
ai tools demonstartion for schools and inter college

Kotlin REST & GraphQL API

  • 2. About Me ● Blog ○ https://animus.design ● GitLab ○ https://gitlab.com/AnimusDesign ● Job: Tech Lead @ Equinox ● Personal Projects ○ Music Recommendation System ○ Kotlin Examples ○ New Web Framework in Kotlin ○ Content Creation Service Over ten years of experience. With a focus on functional reactive full stack development. Utilizing Kotlin to ease delivering of the domain to the client. Early adopter of multi-platform to share code across multiple targets.
  • 3. What is GraphQL ● GraphQL is a newish API format developed by FaceBook for React. First released in 2015 ○ Primarily used by Javascript Frameworks ● It is strongly typed, with a schema. Allowing for autocompletion, and is self documenting. ● You specify what data you wish to receive. In that vein you can chain multiple queries, without hitting multiple endpoints. ○ Think of it as akin to sql, with functions instead of a language, but you still specify the returns. ● Advanced ○ Can whitelist queries run in production, limiting ad hoc queries. ○ Can build fragments that act as building blocks inside queries. ● Hacker News Discussion on Switching to GraphQL
  • 6. GraphQL Additions ● GraphQL is a specification, additional libraries/frameworks expand its capabilities. ○ Much like an api gateway for REST, joining microservices. ● This is required because the structure of the data is put on the client instead of the server. ● Relay & Relay Modern from FaceBook, allow data binding to components, caching, etc. ● Apollo acts as a GraphQL API GateWay, with monitoring, alerting, and other features. ○ Client supports caching, binding, and managing local state of the application. ● Important ○ Support outside of JavaScript is weak. As an example JVM doesn’t support caching in Apollo, but supports performance tracing. ● I will be focusing on Apollo
  • 7. GraphQL Schema Stitching ● Schema stitching combines several GraphQL end points into one. ● Equivalent to an api gateway. ● When making a query, it will route the request to the proper service.
  • 8. Why is the Framework Important? ● Isomorphic rendering, or server side rendering with GraphQL ● Caching, to limit hitting the primary data source repeatedly. ● How the javascript/Client interacts with the data layer. ● Whether the build process verifies the requested fields are in the schema. ● Performance monitoring, and trace monitoring. ● Schema stitching, or combining multiple graphql services together. In short your framework choice will largely dictate your backend language.
  • 9. Why use GraphQL ● You’re using a javascript web/mobile framework. ● With Apollo client for web and mobile. ● Limits the data requested. ● Can whitelist queries, verifying what is queried in production. ● Less data requested, means less transfer. ○ Customize the data you retrieve from the data source. ● Reduce number of api calls. ● Strongly typed response. ● No need to maintain / generate swagger documentation.
  • 10. Why Apollo? ● Polyglot support Swift (iOS), Kotlin (Android), JavaScript (vue, react, angular) clients. ● Wide range of backend server support ○ With varying levels of support.. ■ Tracing is supported in Java and other languages, see here for latest supported languages. ○ Caching javascript only at this time. ● Integration with pager-duty and data dog, easing monitoring. ● Shiny dashboard with pretty lines. ● Better community integration, things like React router for isomorphic rendering. ● Professional support
  • 11. Backend MakeUp ● API ○ Jooby ■ HTTP Routing Library ○ Java-GraphQL ■ FrameWork for GraphQL ○ Graphql-spqr ■ Java 8+ Bindings easing definition, but not targeted towards kotlin. ○ Jooq ■ Database layer that acts as a thin layer for operations. ○ Hikari CP ■ Connection pooling for the database. ● Apollo ○ GraphQL GateWay Server ○ Performance Monitoring ● Graphite + Grafana Monitoring
  • 12. Project Structure ● Base Structure we will be working with. ● api ○ Is the backend GraphQL and Rest layer. ● database ○ The database interaction library. ● Web ○ A react frontend ● Anything gradle is build related.
  • 13. DataBase ● Auto generated java classes via jooq. ● No hand writing or mapping to database. ● Generated via a gradle build file. ● Utilizes environment variables to integrate with your pipeline. ● Looks strikingly like SQL.
  • 14. Data Model ● Name Basic - Provides information on actors, writers, crews, etc. ● Title Basic - Common information on a title can be a movie or tv episode. ● Title AKA - Title also known as a table of other title names, not used. ● Title Episode - Maps a parent title (TV Show), to seasons, episode numbers, and episode ids. ● Title Crew - Takes a title id and provides a list of directors and writers. Pulled from IMBD sample data set. Small sample set of movies, tv shows, writers, directors, and actors. https://www.imdb.com/interfaces/
  • 15. Jooby: HTTP API GraphQl & Rest ● GraphQL requires a single POST or GET endpoint ● Supports multi versioned REST endpoints ● Swagger and RAML generation for Rest ● Metrics, supporting graphite, data dog and more. ● Docker support ● A number of other modules ● Running on Netty an asynchronous event server ○ Can run on other servers. ● Support for hot reloading, i.e. automatic recompilation.
  • 16. There are a Plethora of HTTP Services Choose what works for you! ● Vertx ● DropWizard ● Javalin ● Spark ● Ktor ● I’m sure I’m forgetting something.
  • 17. Jooby Making End Points ● Closures, lambda functions included in a type safe DSL builder. ● Supports MVC class based method (My preference)
  • 18. Jooby Closure REST EndPoint ● A type safe builder for your end points in the run section for Jooby. ● Supports arguments and parameters. ● Each http verb is a seperate function
  • 19. Class MVC Rest EndPoint - Each Class is a path - Annotated with the HTTP verb - Can annotate with sub path - Automatic conversion to json
  • 20. Single GraphQL EndPoint - Data classes for response and post body. - Read the post body. - Submit to the schema executor - Return response.
  • 21. GraphQL Java ● Strong Community, very active development. ● Support for Apollo (minus caching) and Relay, plus more. ● A number of additions to ease development. ○ https://github.com/graphql-java/awesome-graphql-java ● Can design schema first or classes first. ● Automatic integration with spring.
  • 22. Limitations of GraphQL Java ● Kotlin is not a first class citizen. ● Builders, that feel a bit heavy in comparison to Kotlin Syntax. ● Documentation is a bit scarce. ● Wiring type definitions, to query resolvers is verbose. ● Doesn’t feel like idiomatic Kotlin ○ There is one Wrapper in Kotlin, but it is not overly active ● Enter GraphQL SPQR. ○ An annotation library that makes adding types and queries very simple. ○ The downside is it doesn’t support Kotlin Data Classes ■ Need to fall back to java in some instances. ■ May encounter esoteric bugs with annotations in Kotlin.
  • 23. GraphQL Object Definition ● Basic Java POJO ● Annotations for the Getters
  • 24. Or This Works ● Class constructor with annotations. ● Common class so can be used across platforms. ● This is the JVM implementation.
  • 26. Generating the Schema ● Instantiate the Pet Service a singleton ● Instantiate the schema, passing any singletons you develop.
  • 27. Demo Time ● Data store is using sample data from IMDB ● REST + GraphQL Endpoints ○ Hot Reloading ● Apollo Engine Integration ○ GraphQL Query Tracing ● Grafana showing Jooby metrics ● Docker build ● Maybe a kotlin + react fetching from the API.
  • 29. VertX If you’re looking for a highly concurrent distributed backend layer. Look at VertX. ● Works with an event loop, and worker pools. ○ Passing information through a message bus. ■ Which can be centralized ■ And accessed from a number of languages. ● Can start with just http endpoints and add more later. ● Built in clustering and service discovery. ● First class Kotlin support. ● Polyglot (Java, Kotlin, Groovy, Scala, Javascript, Ruby) ● HTTP end points, as well as custom TCP/UDP services. ● Akin to an actor model. ● Great GraphQL support.
  • 30. Changing your data store ● Neo4j (graph database has built in graphql support). ● In built use of GraphQL Java and Apollo ● But you have to change your data store… ● Called the Grand Stack
  • 31. Could we create new annotations?

Editor's Notes

  • #14: Show Jooq Build gradle in idea
  • #16: Walk through