Microservices in Scala: Spray

Łukasz Sowa
Łukasz SowaCo-founder, managing partner at Iterators
Microservices in Spray 
Łukasz Sowa @luksow 
Jacek Głodek @jacekglodek
Spray 
● Client- & server-side REST/HTTP libs 
● Multiple layers – low-level to DSL 
● Really fast (check out benchmarks!) 
● „Acquired” by Typesafe 
● Spray => akka-http 
– Reactive streams 
– New building block for Play 
● Well-suited for REST microservices
Spray 
● HttpRequest => HttpResponse 
● Different levels of abstraction, focus: DSL 
● Key concepts 
– Routing directives 
– Marshalling
Spray - routing 
● Directives 
– Transform, extract, filter, side-effecting 
– Composable 
– Concatanable
Spray - routing 
● Useful directives 
– path, pathPrefix 
– get, post, put, delete, patch 
– parameters 
– formFields 
– entity 
– logRequestResponse 
– complete (!)
Coding! 
● Try out at least following combinations: 
1) pathPrefix + path (with extracting) 
2) get + parameters 
3) post + formFields
Spray - marshalling 
● Return anything that is marshalable 
● String (OK(value)) 
● HttpEntity 
● Option[T] (OK(T) vs. NotFound(T)) 
● Either[A, B] (OK(A) vs. OK(B)) 
● Future[T] (OK(T) – success vs. InternalServerError) 
● Loads of predefined stuff, ex. JSON 
● You can write your own!
Coding! 
1) Try Option & Future marshallers 
2) Use JSON marshaller to return JSON 
3) Combine 1) & 2) 
4) Use entity directive 
5) Add validation 
6) Time to create real microservices, yay!
Registration microservice 
● POST /auth/account 
● JSON { login: l, password: p, passwordConfirmation: pC } 
● OK + { login: l, authToken: aT } 
● BadRequest 
● POST /auth/session 
● Form login: l, password: p 
● OK + { login: l, authToken: aT } 
● Forbidden 
● GET /auth/account (H: AuthToken: aT) 
● OK + { login: l, authToken: aT, … } 
● Forbidden
Links microservice 
● Authenticate all the things! (Forbidden) 
● POST /links/ 
● JSON { url: u, description: d } 
● Save: ^ + date + author 
● GET /links/:id 
● JSON { url: u, description: d, date: dt, author: a } 
● GET /links?limit=N&offset=M 
● JSON { links: [url] }
1 of 10

Recommended

Microservices 101: opportunities, dilemmas and problems by
Microservices 101: opportunities, dilemmas and problemsMicroservices 101: opportunities, dilemmas and problems
Microservices 101: opportunities, dilemmas and problemsŁukasz Sowa
1.8K views39 slides
Microservices in Scala - theory & practice by
Microservices in Scala - theory & practiceMicroservices in Scala - theory & practice
Microservices in Scala - theory & practiceŁukasz Sowa
1.6K views16 slides
KubeCon EU 2019 - P2P Docker Image Distribution in Hybrid Cloud Environment w... by
KubeCon EU 2019 - P2P Docker Image Distribution in Hybrid Cloud Environment w...KubeCon EU 2019 - P2P Docker Image Distribution in Hybrid Cloud Environment w...
KubeCon EU 2019 - P2P Docker Image Distribution in Hybrid Cloud Environment w...Yiran Wang
250 views31 slides
Logmanagement with Icinga2 and ELK by
Logmanagement with Icinga2 and ELKLogmanagement with Icinga2 and ELK
Logmanagement with Icinga2 and ELKIcinga
5.7K views34 slides
Mongo db - How we use Go and MongoDB by Sam Helman by
Mongo db - How we use Go and MongoDB by Sam HelmanMongo db - How we use Go and MongoDB by Sam Helman
Mongo db - How we use Go and MongoDB by Sam HelmanHakka Labs
10.6K views34 slides
Writing a fast HTTP parser by
Writing a fast HTTP parserWriting a fast HTTP parser
Writing a fast HTTP parserfukamachi
7.3K views51 slides

More Related Content

What's hot

Ratpack JVM_MX Meetup February 2016 by
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Domingo Suarez Torres
1.1K views30 slides
Intro to GO (Bangkok Launchpad 2014) by
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)Matthew Campbell
699 views28 slides
Developing high-performance network servers in Lisp by
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in LispVladimir Sedach
4K views29 slides
Fluentd meetup by
Fluentd meetupFluentd meetup
Fluentd meetupSadayuki Furuhashi
2.4K views21 slides
fluent-plugin-beats at Elasticsearch meetup #14 by
fluent-plugin-beats at Elasticsearch meetup #14fluent-plugin-beats at Elasticsearch meetup #14
fluent-plugin-beats at Elasticsearch meetup #14N Masahiro
6.8K views10 slides
HornetQ Presentation On JBoss World 2009 by
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009jarfield
1.6K views31 slides

What's hot(20)

Intro to GO (Bangkok Launchpad 2014) by Matthew Campbell
Intro to GO (Bangkok Launchpad 2014)Intro to GO (Bangkok Launchpad 2014)
Intro to GO (Bangkok Launchpad 2014)
Matthew Campbell699 views
Developing high-performance network servers in Lisp by Vladimir Sedach
Developing high-performance network servers in LispDeveloping high-performance network servers in Lisp
Developing high-performance network servers in Lisp
Vladimir Sedach4K views
fluent-plugin-beats at Elasticsearch meetup #14 by N Masahiro
fluent-plugin-beats at Elasticsearch meetup #14fluent-plugin-beats at Elasticsearch meetup #14
fluent-plugin-beats at Elasticsearch meetup #14
N Masahiro6.8K views
HornetQ Presentation On JBoss World 2009 by jarfield
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009
jarfield1.6K views
RSYSLOG v8 improvements and how to write plugins in any language. by Rainer Gerhards
RSYSLOG v8 improvements and how to write plugins in any language.RSYSLOG v8 improvements and how to write plugins in any language.
RSYSLOG v8 improvements and how to write plugins in any language.
Rainer Gerhards11.3K views
Fluentd v1 and future at techtalk by N Masahiro
Fluentd v1 and future at techtalkFluentd v1 and future at techtalk
Fluentd v1 and future at techtalk
N Masahiro1.2K views
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain by Eran Harel
OB1K - New, Better, Faster, Devops Friendly Java container by OutbrainOB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
OB1K - New, Better, Faster, Devops Friendly Java container by Outbrain
Eran Harel2.2K views
Like loggly using open source by Thomas Alrin
Like loggly using open sourceLike loggly using open source
Like loggly using open source
Thomas Alrin3.2K views
HTTP::Parser::XS - writing a fast & secure XS module by Kazuho Oku
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS module
Kazuho Oku3.9K views
Stateful stream processing with kafka and samza by George Li
Stateful stream processing with kafka and samzaStateful stream processing with kafka and samza
Stateful stream processing with kafka and samza
George Li888 views
Introduction to Redis by Dvir Volk
Introduction to RedisIntroduction to Redis
Introduction to Redis
Dvir Volk121K views
ruby + websocket + haproxy by Mathieu Elie
ruby + websocket + haproxyruby + websocket + haproxy
ruby + websocket + haproxy
Mathieu Elie2K views
Deep Dive into Building a Secure & Multi-tenant SaaS Solution with NATS by NATS
Deep Dive into Building a Secure & Multi-tenant SaaS Solution with NATSDeep Dive into Building a Secure & Multi-tenant SaaS Solution with NATS
Deep Dive into Building a Secure & Multi-tenant SaaS Solution with NATS
NATS465 views
CPAN Gems From The Far East by lestrrat
CPAN Gems From The Far EastCPAN Gems From The Far East
CPAN Gems From The Far East
lestrrat1.4K views

Similar to Microservices in Scala: Spray

Introduction to Node.js by
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsSomkiat Puisungnoen
3.8K views81 slides
Using the new WordPress REST API by
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
3.4K views35 slides
Make BDD great again by
Make BDD great againMake BDD great again
Make BDD great againYana Gusti
84 views32 slides
gRPC and Microservices by
gRPC and MicroservicesgRPC and Microservices
gRPC and MicroservicesJonathan Gomez
3.2K views22 slides
Build reliable, traceable, distributed systems with ZeroMQ by
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQRobin Xiao
4.1K views34 slides

Similar to Microservices in Scala: Spray(20)

Using the new WordPress REST API by Caldera Labs
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
Caldera Labs3.4K views
Make BDD great again by Yana Gusti
Make BDD great againMake BDD great again
Make BDD great again
Yana Gusti84 views
Build reliable, traceable, distributed systems with ZeroMQ by Robin Xiao
Build reliable, traceable, distributed systems with ZeroMQBuild reliable, traceable, distributed systems with ZeroMQ
Build reliable, traceable, distributed systems with ZeroMQ
Robin Xiao4.1K views
Meetup-js-032815 by Joe Devlin
Meetup-js-032815Meetup-js-032815
Meetup-js-032815
Joe Devlin491 views
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai... by François-Guillaume Ribreau
Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...Choisir entre une API  RPC, SOAP, REST, GraphQL?  
Et si le problème était ai...
Choisir entre une API RPC, SOAP, REST, GraphQL? 
Et si le problème était ai...
Node.js 淺談res tful by Simon Su
Node.js 淺談res tfulNode.js 淺談res tful
Node.js 淺談res tful
Simon Su2.4K views
Python tools for testing web services over HTTP by Mykhailo Kolesnyk
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
Mykhailo Kolesnyk2.7K views
Simple REST with Dropwizard by Andrei Savu
Simple REST with DropwizardSimple REST with Dropwizard
Simple REST with Dropwizard
Andrei Savu20.9K views
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019 by Viktor Todorov
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
The Recording HTTP Proxy: Not Yet Another Messiah - Bulgaria PHP 2019
Viktor Todorov587 views
Design Web Service API by HungerStation by ArabNet ME
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStation
ArabNet ME1.3K views
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b... by apidays
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays128 views
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P... by Alessandro Molina
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina2.3K views
Node.js streams talk by zladuric
Node.js streams talkNode.js streams talk
Node.js streams talk
zladuric1.6K views

Recently uploaded

Dapr Unleashed: Accelerating Microservice Development by
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice DevelopmentMiroslav Janeski
10 views29 slides
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...Deltares
17 views12 slides
HarshithAkkapelli_Presentation.pdf by
HarshithAkkapelli_Presentation.pdfHarshithAkkapelli_Presentation.pdf
HarshithAkkapelli_Presentation.pdfharshithakkapelli
11 views16 slides
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...Deltares
14 views23 slides
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...Deltares
9 views26 slides
Software evolution understanding: Automatic extraction of software identifier... by
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
7 views33 slides

Recently uploaded(20)

Dapr Unleashed: Accelerating Microservice Development by Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski10 views
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge... by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
DSD-INT 2023 Delft3D FM Suite 2024.01 2D3D - New features + Improvements - Ge...
Deltares17 views
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko... by Deltares
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
DSD-INT 2023 Simulation of Coastal Hydrodynamics and Water Quality in Hong Ko...
Deltares14 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Tridens DevOps by Tridens
Tridens DevOpsTridens DevOps
Tridens DevOps
Tridens9 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra... by Marc Müller
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra....NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
.NET Developer Conference 2023 - .NET Microservices mit Dapr – zu viel Abstra...
Marc Müller38 views
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut... by Deltares
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
DSD-INT 2023 Machine learning in hydraulic engineering - Exploring unseen fut...
Deltares7 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
Navigating container technology for enhanced security by Niklas Saari by Metosin Oy
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
Metosin Oy13 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports

Microservices in Scala: Spray

  • 1. Microservices in Spray Łukasz Sowa @luksow Jacek Głodek @jacekglodek
  • 2. Spray ● Client- & server-side REST/HTTP libs ● Multiple layers – low-level to DSL ● Really fast (check out benchmarks!) ● „Acquired” by Typesafe ● Spray => akka-http – Reactive streams – New building block for Play ● Well-suited for REST microservices
  • 3. Spray ● HttpRequest => HttpResponse ● Different levels of abstraction, focus: DSL ● Key concepts – Routing directives – Marshalling
  • 4. Spray - routing ● Directives – Transform, extract, filter, side-effecting – Composable – Concatanable
  • 5. Spray - routing ● Useful directives – path, pathPrefix – get, post, put, delete, patch – parameters – formFields – entity – logRequestResponse – complete (!)
  • 6. Coding! ● Try out at least following combinations: 1) pathPrefix + path (with extracting) 2) get + parameters 3) post + formFields
  • 7. Spray - marshalling ● Return anything that is marshalable ● String (OK(value)) ● HttpEntity ● Option[T] (OK(T) vs. NotFound(T)) ● Either[A, B] (OK(A) vs. OK(B)) ● Future[T] (OK(T) – success vs. InternalServerError) ● Loads of predefined stuff, ex. JSON ● You can write your own!
  • 8. Coding! 1) Try Option & Future marshallers 2) Use JSON marshaller to return JSON 3) Combine 1) & 2) 4) Use entity directive 5) Add validation 6) Time to create real microservices, yay!
  • 9. Registration microservice ● POST /auth/account ● JSON { login: l, password: p, passwordConfirmation: pC } ● OK + { login: l, authToken: aT } ● BadRequest ● POST /auth/session ● Form login: l, password: p ● OK + { login: l, authToken: aT } ● Forbidden ● GET /auth/account (H: AuthToken: aT) ● OK + { login: l, authToken: aT, … } ● Forbidden
  • 10. Links microservice ● Authenticate all the things! (Forbidden) ● POST /links/ ● JSON { url: u, description: d } ● Save: ^ + date + author ● GET /links/:id ● JSON { url: u, description: d, date: dt, author: a } ● GET /links?limit=N&offset=M ● JSON { links: [url] }