SlideShare una empresa de Scribd logo
1 de 32
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 ?

Más contenido relacionado

La actualidad más candente

Introduction to DevOps and the Practical Use Cases at Credit OK
Introduction to DevOps and the Practical Use Cases at Credit OKIntroduction to DevOps and the Practical Use Cases at Credit OK
Introduction to DevOps and the Practical Use Cases at Credit OKKriangkrai Chaonithi
 
Apache Beam @ GCPUG.TW Flink.TW 20161006
Apache Beam @ GCPUG.TW Flink.TW 20161006Apache Beam @ GCPUG.TW Flink.TW 20161006
Apache Beam @ GCPUG.TW Flink.TW 20161006Randy Huang
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLRodrigo Prates
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL IntroductionSerge Huber
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL StackSashko Stubailo
 
GraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDBGraphQL ♥︎ GraphDB
GraphQL ♥︎ GraphDBGraphRM
 
Adding GraphQL to your existing architecture
Adding GraphQL to your existing architectureAdding GraphQL to your existing architecture
Adding GraphQL to your existing architectureSashko Stubailo
 
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)
Build GraphQL APIs with Graphene (Big Mountain Data & Dev 2019)Ayla Khan
 
REST vs GraphQL
REST vs GraphQLREST vs GraphQL
REST vs GraphQLSquareboat
 
Improving Mobile Payments With Real time Spark
Improving Mobile Payments With Real time SparkImproving Mobile Payments With Real time Spark
Improving Mobile Payments With Real time Sparkdatamantra
 
Introduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceIntroduction to Ruby Native Extensions and Foreign Function Interface
Introduction to Ruby Native Extensions and Foreign Function InterfaceOleksii Sukhovii
 
GraphQL (Graphene-Django)
GraphQL (Graphene-Django)GraphQL (Graphene-Django)
GraphQL (Graphene-Django)Selo Lee
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
Python Streaming Pipelines with Beam on Flink
Python Streaming Pipelines with Beam on FlinkPython Streaming Pipelines with Beam on Flink
Python Streaming Pipelines with Beam on FlinkAljoscha Krettek
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherSashko Stubailo
 
Balkan - data eng meetup - data fusion
Balkan - data eng meetup - data fusionBalkan - data eng meetup - data fusion
Balkan - data eng meetup - data fusionBalkan Misirli
 
Introduction to Modern DevOps Technologies
Introduction to  Modern DevOps TechnologiesIntroduction to  Modern DevOps Technologies
Introduction to Modern DevOps TechnologiesKriangkrai Chaonithi
 
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorWhy UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/MeteorJon Wong
 

La actualidad más candente (20)

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

Similar a Kotlin REST & GraphQL API

GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0Tobias Meixner
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQLVMware Tanzu
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherReact Conf Brasil
 
Marco Liberati - Graph analytics
Marco Liberati - Graph analyticsMarco Liberati - Graph analytics
Marco Liberati - Graph analyticsCodemotion
 
GraphQL API Crafts presentation
GraphQL API Crafts presentationGraphQL API Crafts presentation
GraphQL API Crafts presentationSudheer J
 
OpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonOpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonHostedbyConfluent
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingSashko Stubailo
 
GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0Tobias Meixner
 
Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)NerdWalletHQ
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Kaxil Naik
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021Soham Dasgupta
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Waysmalltown
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationstakezoe
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLKnoldus Inc.
 

Similar a Kotlin REST & GraphQL API (20)

GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0GraphQL Bangkok meetup 5.0
GraphQL Bangkok meetup 5.0
 
Next.js with drupal, the good parts
Next.js with drupal, the good partsNext.js with drupal, the good parts
Next.js with drupal, the good parts
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
Marco Liberati - Graph analytics
Marco Liberati - Graph analyticsMarco Liberati - Graph analytics
Marco Liberati - Graph analytics
 
GraphQL API Crafts presentation
GraphQL API Crafts presentationGraphQL API Crafts presentation
GraphQL API Crafts presentation
 
OpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit LondonOpenLineage for Stream Processing | Kafka Summit London
OpenLineage for Stream Processing | Kafka Summit London
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema Stitching
 
GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0GraphQL Bangkok Meetup 6.0
GraphQL Bangkok Meetup 6.0
 
Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
Apache Airflow in the Cloud: Programmatically orchestrating workloads with Py...
 
Netty training
Netty trainingNetty training
Netty training
 
Netty training
Netty trainingNetty training
Netty training
 
GraphQL-ify your APIs - Devoxx UK 2021
 GraphQL-ify your APIs - Devoxx UK 2021 GraphQL-ify your APIs - Devoxx UK 2021
GraphQL-ify your APIs - Devoxx UK 2021
 
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps WayDevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
DevOpsDays Taipei 2019 - Mastering IaC the DevOps Way
 
Google Cloud Dataflow
Google Cloud DataflowGoogle Cloud Dataflow
Google Cloud Dataflow
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 

Último

WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Último (20)

WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

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?

Notas del editor

  1. Show Jooq Build gradle in idea
  2. Walk through