SlideShare a Scribd company logo
1 of 42
Download to read offline
ITERATORSI T E R AT O R S @luksow
Practical Akka HTTP
introduction
Łukasz Sowa, XI Tricity Scala User Group
I T E R AT O RITERATORSI T E R AT O R S @luksow
Hi, I'm Łukasz
● Co-founder, dev @ Iterators (https://iterato.rs)
● Highly concurrent & distributed systems (MSA)
● ScalaWAW organizer (please attend!)
● Pizza, beer & football lover
● http://luksow.com
● contact@luksow.com
● @luksow
ITERATORSI T E R AT O R S @luksow
What's in it for you?
● Learn
– What Akka HTTP is
– Key architectural concepts
– When & how to use it
– How does it fit in the Scala ecosystem
● Takeaways
– Beginners: ability to start using Akka HTTP
– Advanced: solid foundations for more exploring
I T E R AT O RITERATORSI T E R AT O R S @luksow
Akka HTTP basics
boring facts
ITERATORSI T E R AT O R S @luksow
Akka HTTP – in definition
● Part of Akka project
● HTTP toolkit (server- and client-side)
● On top of akka-actor & akka-stream
● Streams, reactive, backpressure, blah!
● Not a framework – focus: integration layers
● Multiple levels of abstraction (open API)
● Scalable; max throughput, acceptable latency
● Both for Java & Scala
ITERATORSI T E R AT O R S @luksow
Akka HTTP – in implementation
● Fully asynchronous & non-blocking
● Actor-friendly but focused on higher-level
API
● Lightweight
● Modular, testable
● Based on mature spray.io
ITERATORSI T E R AT O R S @luksow
Akka HTTP – in dates
● Spray.io (2011-03 – 2015-06 ✝?)
– Bad chunked-requests support
– Missing features (ex. websockets)
– Hard to develop & debug
● Spray.io acquired by Typesafe (2013-10)
● First preview - 0.4 (2014-06)
– Very experimental, practically unusable
● 'Good enough for evaluation and production' – 1.0 (2015-07)
– No, not really, still very experimental and lacking
● Five months later - 2.0 (2015-12)
– Oh sorry, we changed some interfaces, have a nice migration!
● Akka 2.4.2-RC3 (2016-02)
– Akka HTTP included in main Akka project, only 'half experimental'
ITERATORSI T E R AT O R S @luksow
Akka HTTP – in parts
● akka-http-core
– Low-level server & client-side HTTP implementation
● akka-http
– High-level API: (un)marshalling, (de)compression, DSL
● akka-http-testkit
– Utilities for testing server-side implementation
● akka-http-spray-json
– Glue-code for (de)serialization from/to JSON with spray-json
● akka-http-xml
– Glue-code for (de)serialization from/to XML with scala-xml
I T E R AT O RITERATORSI T E R AT O R S @luksow
Inside Akka HTTP
HTTP model, server, DSL,
client, (un)marshalling, testkit
I T E R AT O RITERATORSI T E R AT O R S @luksow
HTTP model
● Fully immutable, case-class-based
● Abstraction for most HTTP things (types!)
● Little logic inside
● Lots of predefined types – common media type,
status codes, encodings etc.
● Open for extensions
● Still very efficient parsing & rendering
● Drawback? Your clients and connected services have
to obey the standard (and bugs happen too!)
I T E R AT O RITERATORSI T E R AT O R S @luksow
HTTP model – examples (1)
I T E R AT O RITERATORSI T E R AT O R S @luksow
HTTP model - examples (2)
I T E R AT O RITERATORSI T E R AT O R S @luksow
HTTP model - examples (3)
I T E R AT O RITERATORSI T E R AT O R S @luksow
Serving – the streams way
I T E R AT O RITERATORSI T E R AT O R S @luksow
Serving – the functional way
I T E R AT O RITERATORSI T E R AT O R S @luksow
Serving – the hard way
Flow[ByteString, ByteString, _]
I T E R AT O RITERATORSI T E R AT O R S @luksow
Serving – example
Full example: https://github.com/theiterators/cors-buster
I T E R AT O RITERATORSI T E R AT O R S @luksow
Serving – the nice way
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL
● Internal domain specific language for
routing
● How most services are actually written
● Layer to the application (business logic)
● Type safe but flexible
● Not just routing – behaviour definition
● Very composable
● Fun, powerful and looks sexy!
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL - example
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL – directives (1)
● type Route = RequestContext ⇒
Future[RouteResult]
● abstract class Directive[L]
● def complete(m: ⇒
ToResponseMarshallable): StandardRoute
● def reject(rejections: Rejection*):
StandardRoute
● def fail(error: Throwable):
Future[RouteResult]
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL – directives (2)
● ~136 predefined directives
● Roles: extracting, filtering, transforming
request or response, side-effecting
● Create your own by composing (| and &
operators) or writing from scratch
● Beaware: it takes time to fully understand
how directives work
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL – custom directive
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL – rejections
● Rejections
– Are produced by directives
– Travel down the routing structure
– Can be cancelled
– Must be handled if no route completes request
– Can be extended
– trait RejectionHandler extends (immutable.Seq[Rejection] ⇒
Option[Route])
– Handling rejection = transforming it into response (probably
with some error code etc.)
– Ex. MethodRejection, AuthorizationFailedRejection,
MissingCookieRejection, MissingQueryParamRejection
I T E R AT O RITERATORSI T E R AT O R S @luksow
Routing DSL – failures
● Failures (or exceptions)
– Are triggered by exceptions or fail(...)
– Travel up the routing structre
– Can be handled by handleExceptions
directive or top-level ExceptionHandler
– trait ExceptionHandler extends
PartialFunction[Throwable, Route]
– Can be used to simplify flow (not very nice) –
ex. for validation
I T E R AT O RITERATORSI T E R AT O R S @luksow
Client
● Connection-level client
– Full control over connection and
request/response scheduling
● Host-level client
– Akka manages connection pool to one
specific host
● Request-level
– Akka performs all connection management
I T E R AT O RITERATORSI T E R AT O R S @luksow
Connection-level client
● Stream-based
● Enables
– HTTP persistent connection
– HTTP pipelining
I T E R AT O RITERATORSI T E R AT O R S @luksow
Host-level client
● Stream-based
● Some complexities around pool
configuration and materialization
I T E R AT O RITERATORSI T E R AT O R S @luksow
Request-level client
● Super easy to use
● What you usually need
● Notice request-building DSL!
I T E R AT O RITERATORSI T E R AT O R S @luksow
(Un)marshalling (1)
● Marshalling – high level → low (wire) level
– ToEntityMarshaller[T]
– ToHeadersAndEntityMarshaller[T]
– ToResponseMarshaller[T]
– ToRequestMarshaller[T]
● Unmarshalling – low (wire) level → high level
– FromEntityUnmarshaller[T]
– FromMessageUnmarshaller[T]
– FromResponseUnmarshaller[T]
– FromRequestUnmarshaller[T]
– FromStringUnmarshaller[T]
– FromStrictFormFieldUnmarshaller[T]
I T E R AT O RITERATORSI T E R AT O R S @luksow
(Un)marshalling (2)
● Many predefined (un)marshallers (also for
generic types)
● Extensible
● JSON and XML support in additional
packages
● Type-class approach – implicit resolution
● Cryptic error messages
I T E R AT O RITERATORSI T E R AT O R S @luksow
Testkit
● Very simple and straightforward
● Allows to assert responses returned for
given requests
● Integrates well with specs2, ScalaTest
I T E R AT O RITERATORSI T E R AT O R S @luksow
Everyday Akka HTTP
some additional remarks
I T E R AT O RITERATORSI T E R AT O R S @luksow
Akka HTTP in Scala world (1)
● Again: it's not a framework
● Not a competition for Play
– Akka HTTP is going to be Play's (2.5.X?)
backend
● Competition: Spray.io, Finagle, Scalatra,
Unfiltered?
● Backed by Lightbend (Typesafe)
I T E R AT O RITERATORSI T E R AT O R S @luksow
Akka HTTP in Scala world (2)
● Where it excels
– Integration layers
– Microservices
– Pure REST APIs
● Where it falls short
– Fully-fledged web applications (with server-
side template generation)
– IMO still lacks maturity
I T E R AT O RITERATORSI T E R AT O R S @luksow
Notable community projects
● https://github.com/softwaremill/akka-http-session
● https://github.com/hseeberger/akka-sse
● https://github.com/hseeberger/akka-http-json
● Not too many
● So roll up your sleeves! :)
● But integrates seamlessly with almost anything
● Lots of educational projects exist
I T E R AT O RITERATORSI T E R AT O R S @luksow
Performance
● Spray.io's performance was impressive
– 750K req/sec via Twitter
– More benchmarks by TechEmpower
● Akka HTTP 1.0 was roughly 10x slower
● Akka HTTP 2.4.2-RC2 75% of Spray's perf
– “this is not the end of the performance work,
we have only just begun”
● But those benchmarks, you know…
I T E R AT O RITERATORSI T E R AT O R S @luksow
Conclusions
tldr;
I T E R AT O RITERATORSI T E R AT O R S @luksow
What was skipped?
● Streams stuff (persistent connections,
pipelining, backpressure etc.)
● Low-level internals
● SSL/TLS support
● Very nice Websocket support
● Probably bunch of other important things
I T E R AT O RITERATORSI T E R AT O R S @luksow
What to remember?
● Akka HTTP is (probably) the hottest Scala HTTP toolkit
● Built on very solid foundations
● Features all the building blocks needed for well-
designed HTTP services
● Provides both low- and high-level (DSLs!) interfaces
for almost everything
● Reactive streams included
● Still lacks maturity
● Easy to start with but hard to master
● Fun to use!
I T E R AT O RITERATORSI T E R AT O R S @luksow
How to start?
● Start coding right away
● Have fun
● Discover best practices along the way
● http://doc.akka.io/docs/akka-stream-and-http-experimental/current/scala/http/index.html
● http://doc.akka.io/api/akka-stream-and-http-experimental/2.0.3/
● https://github.com/theiterators/akka-http-microservice + tutorial
● https://github.com/theiterators/reactive-microservices + tutorial
● Lightbend Activator – search akka-http
● https://groups.google.com/forum/#!forum/akka-user
● https://gitter.im/akka/akka
● Sign up for a newsletter on http://luksow.com to get notified about big tutorial I'm preparing
I T E R AT O RITERATORSI T E R AT O R S @luksow
Thanks!
● Łukasz Sowa
● https://iterato.rs
● http://luksow.com
● contact@luksow.com
● @luksow
Questions?

More Related Content

What's hot

Display earthquakes with Akka-http
Display earthquakes with Akka-httpDisplay earthquakes with Akka-http
Display earthquakes with Akka-httpPierangelo Cecchetto
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Reactivesummit
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesLightbend
 
How to manage large amounts of data with akka streams
How to manage large amounts of data with akka streamsHow to manage large amounts of data with akka streams
How to manage large amounts of data with akka streamsIgor Mielientiev
 
Asynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbsAsynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbsAnil Gursel
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015mircodotta
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaBack-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaAkara Sucharitakul
 
Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Eric Torreborre
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
Serverless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsServerless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsStreamNative
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Lightbend
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Developing Secure Scala Applications With Fortify For Scala
Developing Secure Scala Applications With Fortify For ScalaDeveloping Secure Scala Applications With Fortify For Scala
Developing Secure Scala Applications With Fortify For ScalaLightbend
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterKonstantin Tsykulenko
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japaneseKonrad Malawski
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka StreamsJohan Andrén
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in ScalaAlex Payne
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldKonrad Malawski
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 
Zoo keeper in the wild
Zoo keeper in the wildZoo keeper in the wild
Zoo keeper in the wilddatamantra
 

What's hot (20)

Display earthquakes with Akka-http
Display earthquakes with Akka-httpDisplay earthquakes with Akka-http
Display earthquakes with Akka-http
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
 
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous ArchitecturesUnderstanding Akka Streams, Back Pressure, and Asynchronous Architectures
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
 
How to manage large amounts of data with akka streams
How to manage large amounts of data with akka streamsHow to manage large amounts of data with akka streams
How to manage large amounts of data with akka streams
 
Asynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbsAsynchronous Orchestration DSL on squbs
Asynchronous Orchestration DSL on squbs
 
Akka streams scala italy2015
Akka streams scala italy2015Akka streams scala italy2015
Akka streams scala italy2015
 
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & KafkaBack-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
 
Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014Specs2 whirlwind tour at Scaladays 2014
Specs2 whirlwind tour at Scaladays 2014
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Serverless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar FunctionsServerless Event Streaming with Pulsar Functions
Serverless Event Streaming with Pulsar Functions
 
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Developing Secure Scala Applications With Fortify For Scala
Developing Secure Scala Applications With Fortify For ScalaDeveloping Secure Scala Applications With Fortify For Scala
Developing Secure Scala Applications With Fortify For Scala
 
Developing distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka ClusterDeveloping distributed applications with Akka and Akka Cluster
Developing distributed applications with Akka and Akka Cluster
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
Zoo keeper in the wild
Zoo keeper in the wildZoo keeper in the wild
Zoo keeper in the wild
 

Viewers also liked

Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPRafal Gancarz
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickZalando Technology
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster OpenCredo
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsNLJUG
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Evan Chan
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Microservices in Scala - theory & practice
Microservices in Scala - theory & practiceMicroservices in Scala - theory & practice
Microservices in Scala - theory & practiceŁukasz Sowa
 
Microservices 101: opportunities, dilemmas and problems
Microservices 101: opportunities, dilemmas and problemsMicroservices 101: opportunities, dilemmas and problems
Microservices 101: opportunities, dilemmas and problemsŁukasz Sowa
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Reactive microservices with play and akka
Reactive microservices with play and akkaReactive microservices with play and akka
Reactive microservices with play and akkascalaconfjp
 
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...Jonas Bonér
 
Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Jonas Bonér
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesKonrad Malawski
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lightbend
 
Microservices in Scala: Spray
Microservices in Scala: SprayMicroservices in Scala: Spray
Microservices in Scala: SprayŁukasz Sowa
 

Viewers also liked (20)

Securing Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTPSecuring Microservices using Play and Akka HTTP
Securing Microservices using Play and Akka HTTP
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster
 
Akka-http
Akka-httpAkka-http
Akka-http
 
Akka HTTP
Akka HTTPAkka HTTP
Akka HTTP
 
Akka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based ApplicationsAkka in Practice: Designing Actor-based Applications
Akka in Practice: Designing Actor-based Applications
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Microservices in Scala - theory & practice
Microservices in Scala - theory & practiceMicroservices in Scala - theory & practice
Microservices in Scala - theory & practice
 
Microservices 101: opportunities, dilemmas and problems
Microservices 101: opportunities, dilemmas and problemsMicroservices 101: opportunities, dilemmas and problems
Microservices 101: opportunities, dilemmas and problems
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Reactive microservices with play and akka
Reactive microservices with play and akkaReactive microservices with play and akka
Reactive microservices with play and akka
 
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...
Akka: Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Ac...
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
 
Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
 
Microservices in Scala: Spray
Microservices in Scala: SprayMicroservices in Scala: Spray
Microservices in Scala: Spray
 

Similar to Practical Akka HTTP - introduction

Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3takezoe
 
Building REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaBuilding REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaKnoldus Inc.
 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQRobin Xiao
 
Scala services in action
Scala services in actionScala services in action
Scala services in actionUnderscore
 
Node.js streams talk
Node.js streams talkNode.js streams talk
Node.js streams talkzladuric
 
From nothing to Prometheus : one year after
From nothing to Prometheus : one year afterFrom nothing to Prometheus : one year after
From nothing to Prometheus : one year afterAntoine Leroyer
 
OUGN 2016: Experiences with REST support on OSB/SOA Suite
OUGN 2016: Experiences with REST support on OSB/SOA SuiteOUGN 2016: Experiences with REST support on OSB/SOA Suite
OUGN 2016: Experiences with REST support on OSB/SOA SuiteJon Petter Hjulstad
 
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz SowaPROIDEA
 
Apache Thrift, a brief introduction
Apache Thrift, a brief introductionApache Thrift, a brief introduction
Apache Thrift, a brief introductionRandy Abernethy
 
Developing OpenResty Framework
Developing OpenResty FrameworkDeveloping OpenResty Framework
Developing OpenResty FrameworkAapo Talvensaari
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in JavaAnirban Majumdar
 
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...Daniel Bryant
 
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-ors
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-orsCharacterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-ors
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-orsSonatype
 
REST - Why, When and How? at AMIS25
REST - Why, When and How? at AMIS25REST - Why, When and How? at AMIS25
REST - Why, When and How? at AMIS25Jon Petter Hjulstad
 
apachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfapachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfssuserbb9f511
 
Distributed tracing 101
Distributed tracing 101Distributed tracing 101
Distributed tracing 101Itiel Shwartz
 
REST Enabling your Oracle Database (2018 Update)
REST Enabling your Oracle Database (2018 Update)REST Enabling your Oracle Database (2018 Update)
REST Enabling your Oracle Database (2018 Update)Jeff Smith
 

Similar to Practical Akka HTTP - introduction (20)

Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
 
Building REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with ScalaBuilding REST API using Akka HTTP with Scala
Building REST API using Akka HTTP with Scala
 
Build reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
 
Scala services in action
Scala services in actionScala services in action
Scala services in action
 
Node.js streams talk
Node.js streams talkNode.js streams talk
Node.js streams talk
 
From nothing to Prometheus : one year after
From nothing to Prometheus : one year afterFrom nothing to Prometheus : one year after
From nothing to Prometheus : one year after
 
Microservices in Clojure
Microservices in ClojureMicroservices in Clojure
Microservices in Clojure
 
OUGN 2016: Experiences with REST support on OSB/SOA Suite
OUGN 2016: Experiences with REST support on OSB/SOA SuiteOUGN 2016: Experiences with REST support on OSB/SOA Suite
OUGN 2016: Experiences with REST support on OSB/SOA Suite
 
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa
4Developers 2015: Mikroserwisy - szanse, dylematy i problemy - Łukasz Sowa
 
Apache Thrift, a brief introduction
Apache Thrift, a brief introductionApache Thrift, a brief introduction
Apache Thrift, a brief introduction
 
Developing OpenResty Framework
Developing OpenResty FrameworkDeveloping OpenResty Framework
Developing OpenResty Framework
 
Server-side Technologies in Java
Server-side Technologies in JavaServer-side Technologies in Java
Server-side Technologies in Java
 
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...
JAX London 2019 "Cloud Native Communication: Using an API Gateway and Service...
 
GÉANT TURN pilot
GÉANT TURN pilotGÉANT TURN pilot
GÉANT TURN pilot
 
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-ors
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-orsCharacterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-ors
Characterizing and Contrasting Kuhn-tey-ner Awr-kuh-streyt-ors
 
REST - Why, When and How? at AMIS25
REST - Why, When and How? at AMIS25REST - Why, When and How? at AMIS25
REST - Why, When and How? at AMIS25
 
apachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfapachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdf
 
Distributed tracing 101
Distributed tracing 101Distributed tracing 101
Distributed tracing 101
 
Ducat
DucatDucat
Ducat
 
REST Enabling your Oracle Database (2018 Update)
REST Enabling your Oracle Database (2018 Update)REST Enabling your Oracle Database (2018 Update)
REST Enabling your Oracle Database (2018 Update)
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

Practical Akka HTTP - introduction

  • 1. ITERATORSI T E R AT O R S @luksow Practical Akka HTTP introduction Łukasz Sowa, XI Tricity Scala User Group
  • 2. I T E R AT O RITERATORSI T E R AT O R S @luksow Hi, I'm Łukasz ● Co-founder, dev @ Iterators (https://iterato.rs) ● Highly concurrent & distributed systems (MSA) ● ScalaWAW organizer (please attend!) ● Pizza, beer & football lover ● http://luksow.com ● contact@luksow.com ● @luksow
  • 3. ITERATORSI T E R AT O R S @luksow What's in it for you? ● Learn – What Akka HTTP is – Key architectural concepts – When & how to use it – How does it fit in the Scala ecosystem ● Takeaways – Beginners: ability to start using Akka HTTP – Advanced: solid foundations for more exploring
  • 4. I T E R AT O RITERATORSI T E R AT O R S @luksow Akka HTTP basics boring facts
  • 5. ITERATORSI T E R AT O R S @luksow Akka HTTP – in definition ● Part of Akka project ● HTTP toolkit (server- and client-side) ● On top of akka-actor & akka-stream ● Streams, reactive, backpressure, blah! ● Not a framework – focus: integration layers ● Multiple levels of abstraction (open API) ● Scalable; max throughput, acceptable latency ● Both for Java & Scala
  • 6. ITERATORSI T E R AT O R S @luksow Akka HTTP – in implementation ● Fully asynchronous & non-blocking ● Actor-friendly but focused on higher-level API ● Lightweight ● Modular, testable ● Based on mature spray.io
  • 7. ITERATORSI T E R AT O R S @luksow Akka HTTP – in dates ● Spray.io (2011-03 – 2015-06 ✝?) – Bad chunked-requests support – Missing features (ex. websockets) – Hard to develop & debug ● Spray.io acquired by Typesafe (2013-10) ● First preview - 0.4 (2014-06) – Very experimental, practically unusable ● 'Good enough for evaluation and production' – 1.0 (2015-07) – No, not really, still very experimental and lacking ● Five months later - 2.0 (2015-12) – Oh sorry, we changed some interfaces, have a nice migration! ● Akka 2.4.2-RC3 (2016-02) – Akka HTTP included in main Akka project, only 'half experimental'
  • 8. ITERATORSI T E R AT O R S @luksow Akka HTTP – in parts ● akka-http-core – Low-level server & client-side HTTP implementation ● akka-http – High-level API: (un)marshalling, (de)compression, DSL ● akka-http-testkit – Utilities for testing server-side implementation ● akka-http-spray-json – Glue-code for (de)serialization from/to JSON with spray-json ● akka-http-xml – Glue-code for (de)serialization from/to XML with scala-xml
  • 9. I T E R AT O RITERATORSI T E R AT O R S @luksow Inside Akka HTTP HTTP model, server, DSL, client, (un)marshalling, testkit
  • 10. I T E R AT O RITERATORSI T E R AT O R S @luksow HTTP model ● Fully immutable, case-class-based ● Abstraction for most HTTP things (types!) ● Little logic inside ● Lots of predefined types – common media type, status codes, encodings etc. ● Open for extensions ● Still very efficient parsing & rendering ● Drawback? Your clients and connected services have to obey the standard (and bugs happen too!)
  • 11. I T E R AT O RITERATORSI T E R AT O R S @luksow HTTP model – examples (1)
  • 12. I T E R AT O RITERATORSI T E R AT O R S @luksow HTTP model - examples (2)
  • 13. I T E R AT O RITERATORSI T E R AT O R S @luksow HTTP model - examples (3)
  • 14. I T E R AT O RITERATORSI T E R AT O R S @luksow Serving – the streams way
  • 15. I T E R AT O RITERATORSI T E R AT O R S @luksow Serving – the functional way
  • 16. I T E R AT O RITERATORSI T E R AT O R S @luksow Serving – the hard way Flow[ByteString, ByteString, _]
  • 17. I T E R AT O RITERATORSI T E R AT O R S @luksow Serving – example Full example: https://github.com/theiterators/cors-buster
  • 18. I T E R AT O RITERATORSI T E R AT O R S @luksow Serving – the nice way
  • 19. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL ● Internal domain specific language for routing ● How most services are actually written ● Layer to the application (business logic) ● Type safe but flexible ● Not just routing – behaviour definition ● Very composable ● Fun, powerful and looks sexy!
  • 20. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL - example
  • 21. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL – directives (1) ● type Route = RequestContext ⇒ Future[RouteResult] ● abstract class Directive[L] ● def complete(m: ⇒ ToResponseMarshallable): StandardRoute ● def reject(rejections: Rejection*): StandardRoute ● def fail(error: Throwable): Future[RouteResult]
  • 22. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL – directives (2) ● ~136 predefined directives ● Roles: extracting, filtering, transforming request or response, side-effecting ● Create your own by composing (| and & operators) or writing from scratch ● Beaware: it takes time to fully understand how directives work
  • 23. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL – custom directive
  • 24. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL – rejections ● Rejections – Are produced by directives – Travel down the routing structure – Can be cancelled – Must be handled if no route completes request – Can be extended – trait RejectionHandler extends (immutable.Seq[Rejection] ⇒ Option[Route]) – Handling rejection = transforming it into response (probably with some error code etc.) – Ex. MethodRejection, AuthorizationFailedRejection, MissingCookieRejection, MissingQueryParamRejection
  • 25. I T E R AT O RITERATORSI T E R AT O R S @luksow Routing DSL – failures ● Failures (or exceptions) – Are triggered by exceptions or fail(...) – Travel up the routing structre – Can be handled by handleExceptions directive or top-level ExceptionHandler – trait ExceptionHandler extends PartialFunction[Throwable, Route] – Can be used to simplify flow (not very nice) – ex. for validation
  • 26. I T E R AT O RITERATORSI T E R AT O R S @luksow Client ● Connection-level client – Full control over connection and request/response scheduling ● Host-level client – Akka manages connection pool to one specific host ● Request-level – Akka performs all connection management
  • 27. I T E R AT O RITERATORSI T E R AT O R S @luksow Connection-level client ● Stream-based ● Enables – HTTP persistent connection – HTTP pipelining
  • 28. I T E R AT O RITERATORSI T E R AT O R S @luksow Host-level client ● Stream-based ● Some complexities around pool configuration and materialization
  • 29. I T E R AT O RITERATORSI T E R AT O R S @luksow Request-level client ● Super easy to use ● What you usually need ● Notice request-building DSL!
  • 30. I T E R AT O RITERATORSI T E R AT O R S @luksow (Un)marshalling (1) ● Marshalling – high level → low (wire) level – ToEntityMarshaller[T] – ToHeadersAndEntityMarshaller[T] – ToResponseMarshaller[T] – ToRequestMarshaller[T] ● Unmarshalling – low (wire) level → high level – FromEntityUnmarshaller[T] – FromMessageUnmarshaller[T] – FromResponseUnmarshaller[T] – FromRequestUnmarshaller[T] – FromStringUnmarshaller[T] – FromStrictFormFieldUnmarshaller[T]
  • 31. I T E R AT O RITERATORSI T E R AT O R S @luksow (Un)marshalling (2) ● Many predefined (un)marshallers (also for generic types) ● Extensible ● JSON and XML support in additional packages ● Type-class approach – implicit resolution ● Cryptic error messages
  • 32. I T E R AT O RITERATORSI T E R AT O R S @luksow Testkit ● Very simple and straightforward ● Allows to assert responses returned for given requests ● Integrates well with specs2, ScalaTest
  • 33. I T E R AT O RITERATORSI T E R AT O R S @luksow Everyday Akka HTTP some additional remarks
  • 34. I T E R AT O RITERATORSI T E R AT O R S @luksow Akka HTTP in Scala world (1) ● Again: it's not a framework ● Not a competition for Play – Akka HTTP is going to be Play's (2.5.X?) backend ● Competition: Spray.io, Finagle, Scalatra, Unfiltered? ● Backed by Lightbend (Typesafe)
  • 35. I T E R AT O RITERATORSI T E R AT O R S @luksow Akka HTTP in Scala world (2) ● Where it excels – Integration layers – Microservices – Pure REST APIs ● Where it falls short – Fully-fledged web applications (with server- side template generation) – IMO still lacks maturity
  • 36. I T E R AT O RITERATORSI T E R AT O R S @luksow Notable community projects ● https://github.com/softwaremill/akka-http-session ● https://github.com/hseeberger/akka-sse ● https://github.com/hseeberger/akka-http-json ● Not too many ● So roll up your sleeves! :) ● But integrates seamlessly with almost anything ● Lots of educational projects exist
  • 37. I T E R AT O RITERATORSI T E R AT O R S @luksow Performance ● Spray.io's performance was impressive – 750K req/sec via Twitter – More benchmarks by TechEmpower ● Akka HTTP 1.0 was roughly 10x slower ● Akka HTTP 2.4.2-RC2 75% of Spray's perf – “this is not the end of the performance work, we have only just begun” ● But those benchmarks, you know…
  • 38. I T E R AT O RITERATORSI T E R AT O R S @luksow Conclusions tldr;
  • 39. I T E R AT O RITERATORSI T E R AT O R S @luksow What was skipped? ● Streams stuff (persistent connections, pipelining, backpressure etc.) ● Low-level internals ● SSL/TLS support ● Very nice Websocket support ● Probably bunch of other important things
  • 40. I T E R AT O RITERATORSI T E R AT O R S @luksow What to remember? ● Akka HTTP is (probably) the hottest Scala HTTP toolkit ● Built on very solid foundations ● Features all the building blocks needed for well- designed HTTP services ● Provides both low- and high-level (DSLs!) interfaces for almost everything ● Reactive streams included ● Still lacks maturity ● Easy to start with but hard to master ● Fun to use!
  • 41. I T E R AT O RITERATORSI T E R AT O R S @luksow How to start? ● Start coding right away ● Have fun ● Discover best practices along the way ● http://doc.akka.io/docs/akka-stream-and-http-experimental/current/scala/http/index.html ● http://doc.akka.io/api/akka-stream-and-http-experimental/2.0.3/ ● https://github.com/theiterators/akka-http-microservice + tutorial ● https://github.com/theiterators/reactive-microservices + tutorial ● Lightbend Activator – search akka-http ● https://groups.google.com/forum/#!forum/akka-user ● https://gitter.im/akka/akka ● Sign up for a newsletter on http://luksow.com to get notified about big tutorial I'm preparing
  • 42. I T E R AT O RITERATORSI T E R AT O R S @luksow Thanks! ● Łukasz Sowa ● https://iterato.rs ● http://luksow.com ● contact@luksow.com ● @luksow Questions?