SlideShare a Scribd company logo
Sandeep Purohit
Software Consultant
Knoldus Software LLP
Sandeep Purohit
Software Consultant
Knoldus Software LLP
Topics CoveredTopics Covered
What is spray
Why we use spray
Spray application architecture
Spray-can HTTP server
Spray-routing
Demo
What is spray
Why we use spray
Spray application architecture
Spray-can HTTP server
Spray-routing
Demo
What is SprayWhat is Spray
spray is an open-source toolkit for building REST/HTTP-based integration
layers on top of Scala and Akka.
Principles of spray :-
● Fully asynchronous, non-blocking
● Actor- and Future-based
● High-performance
● Lightweight
● Modular
● Testable
Why we use sprayWhy we use spray
● To make RESTful web services
● REST should be used if it is very important for you to minimize the coupling
between client and server components in a distributed application.
● This may be the case if your server is going to be used by many different
clients that you do not have control over.
● Simply make a controller layer of MVC architecture
Spray-can Http serverSpray-can Http server
The spray-can HttpServer is scoped with a clear focus on the essential
functionality of an HTTP/1.1 server:
●
Connection management
● Message parsing and header separation
● Timeout management (for requests and connections)
● Response ordering (for transparent pipelining support)
The spray-can HTTP server is implemented by two types of Akka actors,
which sit on top of Akka IO. When you tell spray-can to start a new server
instance on a given port an HttpListener actor is started, which accepts
incoming connections and for each one spawns a new
HttpServerConnection actor, which then manages the connection for the
rest of its lifetime
Starting spray-can Http serverStarting spray-can Http server
// we need an ActorSystem to host our application in
implicit val system = ActorSystem("spray-api-service")
// create and start our service actor
val service = system.actorOf(Props[MyServiceActor], "spray-service")
// start a new HTTP server on port 8080 with our service actor as the handler
IO(Http) ! Http.Bind(service, interface = "localhost", port = 8080)
}
A spray-can HTTP server is started by sending an Http.Bind command to the
Http extension:
Spray-routing
The spray-routing module provides a high-level, very flexible routing DSL for elegantly defining
RESTful web services. Normally you would use it either on top of a spray-can HTTP Server.
Val routes = path("index") {
get {
respondWithMediaType(`text/html`) {
complete {
HttpResponse(OK, "Hello Sandeep ")
}
}
}
}
Directives
Directives are small building blocks of which you can construct arbitrarily
complex route structures. Here is a simple example of a route built from
directives:
A directive does one or more of the following:
● Transform the incoming RequestContext before passing it on to its inner Route
● Filter the RequestContext according to some logic, i.e. only pass on certain
requests and reject all others
● Extract values from the RequestContext and make them available to its inner
Route as “extractions”
● Complete the request
Composing directives
val route: Route =
path("order" / IntNumber) { id =>
get {
complete {
"Received GET request for order " + id
}
} ~
put {
complete {
"Received PUT request for order " + id
}
}
}
you can also use the | operator on directives
Get and put directives are chained together with the ~ operator to form a
higher-level route that serves as the inner Route of the path directive
Parameters
● .? (optional)
● ? "red" (default value)
● ! "blue" (color should be blue)
● .as[Int] (deserialize as a Int)
Query parameters can be either extracted as a String or can be converted
to another type. The parameter name can be supplied either as a String or
as a Symbol. Parameter extraction can be modified to mark a query
parameter as required or optional or to filter requests where a parameter
has a certain value
Get request parameters extract
val route =
parameters('color, 'backgroundColor) { (color, backgroundColor) =>
complete(s"The color is '$color' and the background is '$backgroundColor'")
}
Deserialize the parameters
val route =
parameters('color, 'count.as[Int]) { (color, count) =>
complete(s"The color is '$color' and you have $count of it.")
}
Marshalling
“Marshalling” is the process of converting a higher-level (object) structure
into some kind of lower-level representation, often a “wire format”. Other
popular names for it are “Serialization” or “Pickling”.
In spray “Marshalling” means the conversion of an object of type T into an
HttpEntity
spray-httpx comes with pre-defined Marshallers for the following types:
● Array[Byte]
● Array[Char]
● String
● Option[T]
● Either[A, B]
● Try[T]
● Future[T]
Unmarshalls
Entity Directive
The entity directive works in conjuction with as and spray.httpx.unmarshalling
to convert some serialized “wire format” value into a higher-level object
structure
val route = post {
entity(as[Person]) { person =>
complete(s"Person: ${person.name} - favorite number: $
{person.favoriteNumber}")
}
}
Spray test-kit
For services built with spray-routing spray provides a dedicated test DSL that
makes actor-less testing of route logic easy and convenient. This “route test DSL”
is made available with the spray-testkit module.
"return a 'PONG!' response for GET requests to /ping" in {
Get("/ping") ~> smallRoute ~> check {
responseAs[String] === "PONG!"
}
}
Thank you

More Related Content

What's hot

enteric coating polymers
enteric coating polymersenteric coating polymers
enteric coating polymersaram ismael
 
Aerosol types , mechanisms
Aerosol types , mechanismsAerosol types , mechanisms
Aerosol types , mechanismsNajirRuman
 
Dissolution apparatus.ppt
Dissolution apparatus.pptDissolution apparatus.ppt
Dissolution apparatus.pptVinayak Wani
 
Flow properties of powders
Flow properties of powdersFlow properties of powders
Flow properties of powdersSmita More
 
Quality Control of Aerosols
Quality Control of AerosolsQuality Control of Aerosols
Quality Control of AerosolsAnindya Jana
 
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.Ravindra Lohar
 
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulol
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulolPilot plan scale up for semisolid and parenteral by Khushboo kunkulol
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulolKhushbooKunkulol
 
Pharmaceutical Mixing & Homogenization
Pharmaceutical Mixing & HomogenizationPharmaceutical Mixing & Homogenization
Pharmaceutical Mixing & HomogenizationBikashAdhikari26
 
Pharmaceutical aerosols
Pharmaceutical aerosolsPharmaceutical aerosols
Pharmaceutical aerosolsShivaram
 
Equipments for Pellets
Equipments for PelletsEquipments for Pellets
Equipments for Pelletsbediaman17
 

What's hot (20)

Suspension ppt
Suspension pptSuspension ppt
Suspension ppt
 
enteric coating polymers
enteric coating polymersenteric coating polymers
enteric coating polymers
 
Aerosol types , mechanisms
Aerosol types , mechanismsAerosol types , mechanisms
Aerosol types , mechanisms
 
Roller compactor
Roller compactorRoller compactor
Roller compactor
 
Dissolution apparatus.ppt
Dissolution apparatus.pptDissolution apparatus.ppt
Dissolution apparatus.ppt
 
Microencapsulation
MicroencapsulationMicroencapsulation
Microencapsulation
 
Flow properties of powders
Flow properties of powdersFlow properties of powders
Flow properties of powders
 
Quality Control of Aerosols
Quality Control of AerosolsQuality Control of Aerosols
Quality Control of Aerosols
 
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.
Formulation and Evaluation of Enteric Coated Tablet of Rabeprazole Sodium.
 
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulol
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulolPilot plan scale up for semisolid and parenteral by Khushboo kunkulol
Pilot plan scale up for semisolid and parenteral by Khushboo kunkulol
 
Tablets
TabletsTablets
Tablets
 
Pharmaceutical Mixing & Homogenization
Pharmaceutical Mixing & HomogenizationPharmaceutical Mixing & Homogenization
Pharmaceutical Mixing & Homogenization
 
Pellet technology
Pellet technologyPellet technology
Pellet technology
 
Parenterals
ParenteralsParenterals
Parenterals
 
Friability test ppt
Friability test pptFriability test ppt
Friability test ppt
 
Enteric coating
Enteric coatingEnteric coating
Enteric coating
 
Drug stability and stabilization techniques
Drug stability and stabilization techniquesDrug stability and stabilization techniques
Drug stability and stabilization techniques
 
Pharmaceutical aerosols
Pharmaceutical aerosolsPharmaceutical aerosols
Pharmaceutical aerosols
 
Equipments for Pellets
Equipments for PelletsEquipments for Pellets
Equipments for Pellets
 
Pharmaceutical Excipients
Pharmaceutical Excipients Pharmaceutical Excipients
Pharmaceutical Excipients
 

Viewers also liked

Preparation of solutions
Preparation of solutionsPreparation of solutions
Preparation of solutionsAbigail Sapico
 
Solvents used in pharmacy
Solvents used in pharmacySolvents used in pharmacy
Solvents used in pharmacyZulcaif Ahmad
 
Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)priyanka odela
 
Chap 13 part 1 solutions
Chap 13   part 1 solutionsChap 13   part 1 solutions
Chap 13 part 1 solutionsMalou Mojares
 
Aerosols
AerosolsAerosols
AerosolsRa Bia
 
Pharmaceutical aerosols
Pharmaceutical aerosolsPharmaceutical aerosols
Pharmaceutical aerosolspragatk
 
31 liquid-liquid extraction
31   liquid-liquid extraction31   liquid-liquid extraction
31 liquid-liquid extractionIncopin
 
Liquid liquid extraction
Liquid liquid extractionLiquid liquid extraction
Liquid liquid extractionali alashiri
 
chemistry : Preparation of solution
chemistry : Preparation of solutionchemistry : Preparation of solution
chemistry : Preparation of solutionShahriffah Norainy
 
Solution & Solubility
Solution & SolubilitySolution & Solubility
Solution & Solubilityitutor
 
Ch.13 part 2 syrups, elixirs, spirits
Ch.13   part 2 syrups, elixirs, spiritsCh.13   part 2 syrups, elixirs, spirits
Ch.13 part 2 syrups, elixirs, spiritsMalou Mojares
 

Viewers also liked (15)

Liquid dosage forms
Liquid dosage formsLiquid dosage forms
Liquid dosage forms
 
Preparation of solutions
Preparation of solutionsPreparation of solutions
Preparation of solutions
 
Solvents used in pharmacy
Solvents used in pharmacySolvents used in pharmacy
Solvents used in pharmacy
 
Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)Solvents used pharmaceutically(j.c)
Solvents used pharmaceutically(j.c)
 
Chap 13 part 1 solutions
Chap 13   part 1 solutionsChap 13   part 1 solutions
Chap 13 part 1 solutions
 
Solutions and their types
Solutions and their typesSolutions and their types
Solutions and their types
 
Aerosols
AerosolsAerosols
Aerosols
 
Pharmaceutical aerosols
Pharmaceutical aerosolsPharmaceutical aerosols
Pharmaceutical aerosols
 
31 liquid-liquid extraction
31   liquid-liquid extraction31   liquid-liquid extraction
31 liquid-liquid extraction
 
Liquid liquid extraction
Liquid liquid extractionLiquid liquid extraction
Liquid liquid extraction
 
chemistry : Preparation of solution
chemistry : Preparation of solutionchemistry : Preparation of solution
chemistry : Preparation of solution
 
Liquid-Liquid Extraction
Liquid-Liquid Extraction Liquid-Liquid Extraction
Liquid-Liquid Extraction
 
Aerosols
AerosolsAerosols
Aerosols
 
Solution & Solubility
Solution & SolubilitySolution & Solubility
Solution & Solubility
 
Ch.13 part 2 syrups, elixirs, spirits
Ch.13   part 2 syrups, elixirs, spiritsCh.13   part 2 syrups, elixirs, spirits
Ch.13 part 2 syrups, elixirs, spirits
 

Similar to Spray

Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Mindfire Solutions
 
SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)Pavan Golesar
 
AK 3 web services using apache axis
AK 3   web services using apache axisAK 3   web services using apache axis
AK 3 web services using apache axisgauravashq
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integrationCreate Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integrationRutul Shah
 
All About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksAll About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksMohammad Asif Siddiqui
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataPace Integration
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
2014 Taverna tutorial REST services
2014 Taverna tutorial REST services2014 Taverna tutorial REST services
2014 Taverna tutorial REST servicesmyGrid team
 
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.
 
Rest service in mule
Rest service in mule Rest service in mule
Rest service in mule Harish43
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyManageIQ
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaJignesh Aakoliya
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introductionCommit University
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web servicesNeil Ghosh
 

Similar to Spray (20)

Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)
 
AK 3 web services using apache axis
AK 3   web services using apache axisAK 3   web services using apache axis
AK 3 web services using apache axis
 
Create Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integrationCreate Home Directories on Storage Using WFA and ServiceNow integration
Create Home Directories on Storage Using WFA and ServiceNow integration
 
All About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice FrameworksAll About Microservices and OpenSource Microservice Frameworks
All About Microservices and OpenSource Microservice Frameworks
 
MuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and ODataMuleSoft London Community February 2020 - MuleSoft and OData
MuleSoft London Community February 2020 - MuleSoft and OData
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Rest web services
Rest web servicesRest web services
Rest web services
 
2014 Taverna tutorial REST services
2014 Taverna tutorial REST services2014 Taverna tutorial REST services
2014 Taverna tutorial REST services
 
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
 
Rest service in mule
Rest service in mule Rest service in mule
Rest service in mule
 
Design Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John HardyDesign Summit - RESTful API Overview - John Hardy
Design Summit - RESTful API Overview - John Hardy
 
Overview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company indiaOverview of MVC Framework - by software outsourcing company india
Overview of MVC Framework - by software outsourcing company india
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Rest Service In Mule
Rest Service In Mule Rest Service In Mule
Rest Service In Mule
 
sveltekit-en.pdf
sveltekit-en.pdfsveltekit-en.pdf
sveltekit-en.pdf
 
Express node js
Express node jsExpress node js
Express node js
 
Intro to web services
Intro to web servicesIntro to web services
Intro to web services
 
Mvc
MvcMvc
Mvc
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 

More from Knoldus Inc.

Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterKnoldus Inc.
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Knoldus Inc.
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationKnoldus Inc.
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationKnoldus Inc.
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Knoldus Inc.
 
Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)Knoldus Inc.
 
Clean Code in Test Automation Differentiating Between the Good and the Bad
Clean Code in Test Automation  Differentiating Between the Good and the BadClean Code in Test Automation  Differentiating Between the Good and the Bad
Clean Code in Test Automation Differentiating Between the Good and the BadKnoldus Inc.
 
Integrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test AutomationIntegrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test AutomationKnoldus Inc.
 
State Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptxState Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptxKnoldus Inc.
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxKnoldus Inc.
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)Knoldus Inc.
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxKnoldus Inc.
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingKnoldus Inc.
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionKnoldus Inc.
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxKnoldus Inc.
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptxKnoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus Inc.
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxKnoldus Inc.
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingKnoldus Inc.
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesKnoldus Inc.
 

More from Knoldus Inc. (20)

Using InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in JmeterUsing InfluxDB for real-time monitoring in Jmeter
Using InfluxDB for real-time monitoring in Jmeter
 
Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)Intoduction to KubeVela Presentation (DevOps)
Intoduction to KubeVela Presentation (DevOps)
 
Stakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) PresentationStakeholder Management (Project Management) Presentation
Stakeholder Management (Project Management) Presentation
 
Introduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) PresentationIntroduction To Kaniko (DevOps) Presentation
Introduction To Kaniko (DevOps) Presentation
 
Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)Efficient Test Environments with Infrastructure as Code (IaC)
Efficient Test Environments with Infrastructure as Code (IaC)
 
Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)Exploring Terramate DevOps (Presentation)
Exploring Terramate DevOps (Presentation)
 
Clean Code in Test Automation Differentiating Between the Good and the Bad
Clean Code in Test Automation  Differentiating Between the Good and the BadClean Code in Test Automation  Differentiating Between the Good and the Bad
Clean Code in Test Automation Differentiating Between the Good and the Bad
 
Integrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test AutomationIntegrating AI Capabilities in Test Automation
Integrating AI Capabilities in Test Automation
 
State Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptxState Management with NGXS in Angular.pptx
State Management with NGXS in Angular.pptx
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)OAuth2 Implementation Presentation (Java)
OAuth2 Implementation Presentation (Java)
 
Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...SachinKumar945617
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativePeter Windle
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...EugeneSaldivar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasGeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismDeeptiGupta154
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Spray

  • 1. Sandeep Purohit Software Consultant Knoldus Software LLP Sandeep Purohit Software Consultant Knoldus Software LLP
  • 2. Topics CoveredTopics Covered What is spray Why we use spray Spray application architecture Spray-can HTTP server Spray-routing Demo What is spray Why we use spray Spray application architecture Spray-can HTTP server Spray-routing Demo
  • 3. What is SprayWhat is Spray spray is an open-source toolkit for building REST/HTTP-based integration layers on top of Scala and Akka. Principles of spray :- ● Fully asynchronous, non-blocking ● Actor- and Future-based ● High-performance ● Lightweight ● Modular ● Testable
  • 4. Why we use sprayWhy we use spray ● To make RESTful web services ● REST should be used if it is very important for you to minimize the coupling between client and server components in a distributed application. ● This may be the case if your server is going to be used by many different clients that you do not have control over. ● Simply make a controller layer of MVC architecture
  • 5.
  • 6. Spray-can Http serverSpray-can Http server The spray-can HttpServer is scoped with a clear focus on the essential functionality of an HTTP/1.1 server: ● Connection management ● Message parsing and header separation ● Timeout management (for requests and connections) ● Response ordering (for transparent pipelining support) The spray-can HTTP server is implemented by two types of Akka actors, which sit on top of Akka IO. When you tell spray-can to start a new server instance on a given port an HttpListener actor is started, which accepts incoming connections and for each one spawns a new HttpServerConnection actor, which then manages the connection for the rest of its lifetime
  • 7. Starting spray-can Http serverStarting spray-can Http server // we need an ActorSystem to host our application in implicit val system = ActorSystem("spray-api-service") // create and start our service actor val service = system.actorOf(Props[MyServiceActor], "spray-service") // start a new HTTP server on port 8080 with our service actor as the handler IO(Http) ! Http.Bind(service, interface = "localhost", port = 8080) } A spray-can HTTP server is started by sending an Http.Bind command to the Http extension:
  • 8. Spray-routing The spray-routing module provides a high-level, very flexible routing DSL for elegantly defining RESTful web services. Normally you would use it either on top of a spray-can HTTP Server. Val routes = path("index") { get { respondWithMediaType(`text/html`) { complete { HttpResponse(OK, "Hello Sandeep ") } } } }
  • 9. Directives Directives are small building blocks of which you can construct arbitrarily complex route structures. Here is a simple example of a route built from directives: A directive does one or more of the following: ● Transform the incoming RequestContext before passing it on to its inner Route ● Filter the RequestContext according to some logic, i.e. only pass on certain requests and reject all others ● Extract values from the RequestContext and make them available to its inner Route as “extractions” ● Complete the request
  • 10. Composing directives val route: Route = path("order" / IntNumber) { id => get { complete { "Received GET request for order " + id } } ~ put { complete { "Received PUT request for order " + id } } } you can also use the | operator on directives Get and put directives are chained together with the ~ operator to form a higher-level route that serves as the inner Route of the path directive
  • 11. Parameters ● .? (optional) ● ? "red" (default value) ● ! "blue" (color should be blue) ● .as[Int] (deserialize as a Int) Query parameters can be either extracted as a String or can be converted to another type. The parameter name can be supplied either as a String or as a Symbol. Parameter extraction can be modified to mark a query parameter as required or optional or to filter requests where a parameter has a certain value
  • 12. Get request parameters extract val route = parameters('color, 'backgroundColor) { (color, backgroundColor) => complete(s"The color is '$color' and the background is '$backgroundColor'") } Deserialize the parameters val route = parameters('color, 'count.as[Int]) { (color, count) => complete(s"The color is '$color' and you have $count of it.") }
  • 13. Marshalling “Marshalling” is the process of converting a higher-level (object) structure into some kind of lower-level representation, often a “wire format”. Other popular names for it are “Serialization” or “Pickling”. In spray “Marshalling” means the conversion of an object of type T into an HttpEntity spray-httpx comes with pre-defined Marshallers for the following types: ● Array[Byte] ● Array[Char] ● String ● Option[T] ● Either[A, B] ● Try[T] ● Future[T]
  • 14. Unmarshalls Entity Directive The entity directive works in conjuction with as and spray.httpx.unmarshalling to convert some serialized “wire format” value into a higher-level object structure val route = post { entity(as[Person]) { person => complete(s"Person: ${person.name} - favorite number: $ {person.favoriteNumber}") } }
  • 15. Spray test-kit For services built with spray-routing spray provides a dedicated test DSL that makes actor-less testing of route logic easy and convenient. This “route test DSL” is made available with the spray-testkit module. "return a 'PONG!' response for GET requests to /ping" in { Get("/ping") ~> smallRoute ~> check { responseAs[String] === "PONG!" } }