Book Image

Programming Kotlin

Book Image

Programming Kotlin

Overview of this book

Quickly learn the fundamentals of the Kotlin language and see it in action on the web. Easy to follow and covering the full set of programming features, this book will get you fluent in Kotlin for Android.
Table of Contents (20 chapters)
Programming Kotlin
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface

Implementing a Lagom service


We have seen already how to define a service. The next natural step is to implement the service interface, and this is materialized in the hello-impl project. The HelloServiceImpl class is responsible for implementing your API interface. We have seen this throughout the code snippets listed earlier. One important thing to notice is that all the methods don't actually execute the call, but rather return a method handle via the instance of ServiceCall. The reason behind this approach is to allows function composition in order to achieve a processing pipeline where authentication, authorization, logging, and exception handling can easily be added.

Let's move the focus back to ServiceCall class. From the definition presented already, you can see it takes a request object and returns a CompletionStage<Response>. This container is nothing but a promise the API makes. At some point in the future, the Response will be computed and therefore will be available to...