Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ktor-MongoDB-Altas-KotlinMeetup-PDF.pdf

Avatar for Ian Ian
October 27, 2020

 Ktor-MongoDB-Altas-KotlinMeetup-PDF.pdf

Avatar for Ian

Ian

October 27, 2020

More Decks by Ian

Other Decks in Programming

Transcript

  1. Ian Arbuckle - Android Developer @ CarTrawler Ktor & MongoDB

    Altas Building RESTful APIs with Ktor & MongoDB Altas
  2. What’s special about Ktor? • You can write small microservices

    with less boilerplate • It’s asynchronous and uses DSL • Open source and completely free! • And oh.. should I say fun?
  3. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  4. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  5. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  6. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  7. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  8. val Setup = PipelinePhase("Setup") // Phase for preparing the call,

    and processing attributes val Monitoring = PipelinePhase("Monitoring") // Phase for tracing calls: logging, metrics, error handling etc. val Features = PipelinePhase("Features") // Phase for infrastructure features, most intercept at this phase val Call = PipelinePhase("Call") // Phase for processing a call and sending a response val Fallback = PipelinePhase("Fallback") // Phase for handling unprocessed calls Source: https://ktor.io/docs/lifecycle.html#features
  9. Setup Monitoring Features Call Fallback Request Response Pipeline Phases Source:

    https://www.ximedes.com/2020-09-17/role-based-authorization-in-ktor/
  10. Setup Monitoring Features Call Fallback Request Response Interceptor Interceptor Interceptor

    Interceptor Interceptor Phases Source: https://www.ximedes.com/2020-09-17/role-based-authorization-in-ktor/ Pipeline
  11. routing { get() { /* show homepage */ } get("/conferences")

    { /* show conferences */ } post("/conferences") { /* create a conference */ } }
  12. routing { get() { /* show homepage */ } get("/conferences")

    { /* show conferences */ } post("/conferences") { /* create a conference */ } }
  13. routing { get() { /* show homepage */ } get("/conferences")

    { /* show conferences */ } post("/conferences") { /* create a conference */ } }
  14. routing { get() { /* show homepage */ } get("/conferences")

    { /* show conferences */ } post("/conferences") { /* create a conference */ } }
  15. routing { get() { /* show homepage */ } get("/conferences")

    { /* show conferences */ } post("/conferences") { /* create a conference */ } }
  16. / /METHOD :GET /conferences (METHOD :GET) /conferences (METHOD :POST) routing

    { get() { /* show homepage */ } get("/conferences") { /* show conferences */ } post("/conferences") { /* create a conference */ } } Source: https://www.ximedes.com/2020-09-17/role-based-authorization-in-ktor/
  17. “MongoDB is a general purpose, document-based, distributed database built for

    modern developers and for the cloud era.” - Wikipedia
  18. “MongoDB is a general purpose, document-based, distributed database built for

    modern developers and for the cloud era.” - Wikipedia
  19. “MongoDB is a general purpose, document-based, distributed database built for

    modern developers and for the cloud era.” - Wikipedia
  20. MongoDB Atlas • Formerly known as mLab • Allows you

    to host a database on somebody else’s computer! • Perfect for agile teams who’d rather spend time building apps • Allows you to pick your cloud provider!
  21. • Conference management dashboard • We’re going to create a

    RESTful CRUD app • MongoDB Atlas will be used as the NoSQL cloud database What we’re going to build..
  22. Resources • Official documentation https://ktor.io • Ktor roadmap https://blog.jetbrains.com/ktor/2020/08/10/ktor-roadmap- for-2020-2021/

    • MongoDB Atlas https://www.mongodb.com/cloud/atlas • KMongo a wrapper library for MongoDB https://github.com/Litote/kmongo • Good article on building role based authentication https://ktor.io/docs/ lifecycle.html#features