SlideShare a Scribd company logo
1 of 23
Download to read offline
Scalatra	
  2.2	
  

NOVEMBER	
  2012	
  
2	
  



Short	
  introduc,on	
  
And	
  overview	
  of	
  	
  
New	
  features	
  
What?	
  
●  Rou5ng	
  
●  Params	
  
●  Json4s	
  
●  Akka	
  
●  Atmosphere	
  
●  Commands	
  
Hello,	
  Scalatra	
  
class	
  HelloWorld	
  extends	
  ScalatraServlet	
  {	
  	
  	
  
	
  	
  get("/hello/:name")	
  {	
  
	
  	
  	
  	
  <h1>Hello,	
  {params("name")}</h1>	
  
	
  	
  }	
  
}	
  
Hello,	
  Scalatra:	
  Routes	
  
class	
  HelloWorld	
  extends	
  ScalatraServlet	
  {	
  	
  	
  
	
  	
  get("/hello/:name")	
  {	
  
	
  	
  	
  	
  <h1>Hello,	
  {params("name")}</h1>	
  
	
  	
  }	
  
}	
  

●  Matches	
  GET	
  requests	
  to	
  /hello/*	
  

●  Captures	
  named	
  parameters	
  from	
  the	
  route	
  (here,	
  :name).	
  

●  Matching	
  requests	
  are	
  dispatched	
  to	
  the	
  ac5on.	
  
Hello,	
  Scalatra:	
  Ac,ons	
  
class	
  HelloWorld	
  extends	
  ScalatraServlet	
  {	
  	
  	
  
	
  	
  get("/hello/:name")	
  {	
  
	
  	
  	
  	
  <h1>Hello,	
  {params("name")}</h1>	
  
	
  	
  }	
  
}	
  
●  When	
  a	
  request	
  matches	
  a	
  route,	
  the	
  ac5on	
  is	
  run.	
  
●  A	
  response	
  is	
  generated	
  from	
  the	
  ac5on's	
  result.	
  
   Supports	
  XML	
  literals,	
  Byte	
  arrays,	
  Strings,	
  Files,	
  
   InputStreams.	
  
●  Rendering	
  of	
  ac5on	
  results	
  is	
  customizable.	
  
Hello	
  Scalatra:	
  ScalatraServlet	
  

class	
  HelloWorld	
  extends	
  ScalatraServlet	
  {	
  
	
  	
  get("/hello/:name")	
  {	
  
	
  	
  	
  	
  <h1>Hello,	
  {params("name")}</h1>	
  
	
  	
  }	
  
}	
  
●  ScalatraServlet	
  provides	
  the	
  HTTP	
  DSL.	
  
●  Scalatra	
  2.x	
  is	
  built	
  on	
  Java	
  Servlets,	
  the	
  
   standard	
  web	
  server	
  API	
  for	
  the	
  JVM.	
  
Why	
  Scalatra?	
  
●  Based	
  on	
  Sinatra,	
                 •  Java	
  
   which	
  I	
  like	
  to	
  call	
        •  F#	
  
   "the	
  universal	
  web	
                •  Erlang	
  
   DSL".	
  	
  Clones	
  exist	
  in:	
  
                                             •  Haskell	
  
      •  Ruby	
  
                                             •  Clojure	
  
      •  PHP	
  
                                             •  Bash	
  
      •  Python	
  
                                             •  Many	
  others	
  
      •  JavaScript	
  
Scalatra	
  Philosophy	
  
●  Stateless	
  by	
  default,	
       •  Akka	
  
   sessions	
  if	
  you	
  need	
     •  Atmosphere	
  
   them.	
                             •  Embrace	
  standards	
  
●  Lean	
  by	
  default,	
            •  HTTP	
  
   integra5ons	
  if	
  they're	
      •  JVM	
  
   popular.	
  
                                       •  Scala	
  
     •  Scalate	
  
                                       •  Beginner	
  friendly.	
  
     •  JSON4s	
  
                                       •  Scale	
  with	
  your	
  app	
  
                                          and	
  your	
  exper5se.	
  
Rou,ng	
  in	
  depth:	
  Methods	
  
get("/hello/:name")	
  {	
  "Hi,	
  "+params("name")	
  }	
  
●  Routes	
  start	
  with	
  an	
  HTTP	
  method.	
  
     •  Get	
  /	
  Head	
  /	
  Op5ons	
  /	
  Connect	
  
     •  Post	
  /	
  Put	
  /	
  Patch	
  /	
  Delete	
  /	
  Trace	
  

●  Advanced	
  usage:	
  can	
  call	
  at	
  any5me	
  to	
  register	
  
   routes	
  on	
  the	
  fly.	
  
Rou,ng	
  in	
  depth:	
  Params	
  
get("/hello/:name")	
  {	
  "Hi,	
  "+params("name")	
  }	
  

●  Matches	
  the	
  servlet	
  path.	
  
     •  Pro5p:	
  compose	
  large	
  apps	
  with	
  mul5ple	
  servlets	
  

●  Declare	
  route	
  params	
  with	
  a	
  leading	
  ':’	
  
     •  Matches	
  everything	
  up	
  to	
  next	
  '/',	
  '?',	
  or	
  '#'	
  
Rou,ng	
  in	
  depth:	
  Params	
  
Rou,ng	
  in	
  depth:	
  Splats	
  
get("/hello/*")	
  {	
  multiParams("splat").mkString(",")	
  }	
  

●  Splats get stored in the captures param.

●  If you expect multiple values, you can access it through
   multiParams.
    •  params is just a convenient view of multiParams
Rou,ng	
  in	
  depth:	
  regex	
  
get("""/hello/(w+)""".r)	
  {	
  "Hello,	
  "+params("captures")	
  }	
  

	
  


●      Use if you have a real hairy route that standard
       syntax can't handle.

●      No named groups yet. Java didn't add named
       regexes until version 7!
Rou,ng	
  in	
  depth:	
  booleans	
  
def	
  userAgent	
  =	
  request.getHeader("User-­‐Agent”)	
  

get("/hello/:name",	
  !userAgent.contains("Lynx"))	
  {	
  	
  
   status	
  =	
  403	
  
   "You	
  and	
  your	
  fancy,	
  schmancy	
  browser.	
  Get	
  out.”	
  }	
  


●  Both paths and boolean expressions are
   converted to route matchers. Implicitly
●  A route matches if and only if all route
   matchers match.
Ac,ons	
  in	
  depth:	
  return	
  value	
  

●  The return value of an action becomes the
   body of the response.
	
  
•  It's just a
                                        •  Override
Ac,ons	
  in	
  depth:	
  render	
  pipeline	
  
                                                                      	


protected	
  def	
  renderPipeline:	
  RenderPipeline	
  =	
  {	
  
	
  	
  case	
  bytes:	
  Array[Byte]	
  =>	
  
	
  	
  	
  	
  response.outputStream.write(bytes)	
  
	
  	
  case	
  is:	
  java.io.InputStream	
  =>	
  
	
  	
  	
  	
  using(is)	
  {	
  util.io.copy(_,	
  response.outputStream)	
  }	
  
}	


●  It's just a partial function.
●  Override it. Use orElse to delegate to
   the default.
Ac,ons	
  in	
  depth:	
  mutable	
  
Ac,ons	
  in	
  depth:	
  mutable	
  
get("/hello/:name")	
  {	
  
  status	
  =	
  HttpServletResponse.SC_GONE	
  	
  
  contentType	
  =	
  "text/html”	
  
  <h1>Goodbye,	
  cruel	
  world</h1>	
  }	
  

●  Status and headers are typically set in an
   imperative fashion.	
  
●  Response is thread local. Relax.
Commands	
  
●  Capture	
  input	
  
●  Validate	
  input	
  
Integra,ons:	
  JSON4S	
  
●  Serialize	
  case	
  classes	
  to	
  json	
  
●  Handles	
  xml	
  as	
  well	
  as	
  json	
  
Integra,ons:	
  Akka	
  
●  Takes	
  advantage	
  of	
  servlet	
  3.0	
  async	
  support	
  
Integra,ons:	
  Atmosphere	
  
●  WebSocket	
  	
  
●  Server	
  side	
  events	
  
●  Like	
  socket.io	
  but	
  not	
  socket.io	
  

More Related Content

What's hot

Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camelprajods
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Jukka Zitting
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxClaus Ibsen
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerVladimir Sedach
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A RideBruce Snyder
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelFuseSource.com
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Toolsguest05c09d
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous ApplicationsJohan Edstrom
 
ApacheCon EU 2016 - Apache Camel the integration library
ApacheCon EU 2016 - Apache Camel the integration libraryApacheCon EU 2016 - Apache Camel the integration library
ApacheCon EU 2016 - Apache Camel the integration libraryClaus Ibsen
 
Ruby/rails performance and profiling
Ruby/rails performance and profilingRuby/rails performance and profiling
Ruby/rails performance and profilingDanny Guinther
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the worldHiroshi SHIBATA
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 

What's hot (20)

Event Driven Architecture with Apache Camel
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo2008-12 OJUG JCR Demo
2008-12 OJUG JCR Demo
 
20140925 rails pacific
20140925 rails pacific20140925 rails pacific
20140925 rails pacific
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
 
Ruby on the JVM
Ruby on the JVMRuby on the JVM
Ruby on the JVM
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
Taking Apache Camel For A Ride
Taking Apache Camel For A RideTaking Apache Camel For A Ride
Taking Apache Camel For A Ride
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
ApacheCon EU 2016 - Apache Camel the integration library
ApacheCon EU 2016 - Apache Camel the integration libraryApacheCon EU 2016 - Apache Camel the integration library
ApacheCon EU 2016 - Apache Camel the integration library
 
Ruby/rails performance and profiling
Ruby/rails performance and profilingRuby/rails performance and profiling
Ruby/rails performance and profiling
 
Gems on Ruby
Gems on RubyGems on Ruby
Gems on Ruby
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 

Similar to Scalatra 2.2

Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web FrameworkDaniel Woods
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsSagara Gunathunga
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6Nobuo Danjou
 
apachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfapachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfssuserbb9f511
 
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...StreamNative
 
Design for Scalability in ADAM
Design for Scalability in ADAMDesign for Scalability in ADAM
Design for Scalability in ADAMfnothaft
 
Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012mumrah
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLiteJEAN-GUILLAUME DUJARDIN
 
Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Claus Ibsen
 

Similar to Scalatra 2.2 (20)

Ratpack Web Framework
Ratpack Web FrameworkRatpack Web Framework
Ratpack Web Framework
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 
Logstash
LogstashLogstash
Logstash
 
Follow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHPFollow the White Rabbit - Message Queues with PHP
Follow the White Rabbit - Message Queues with PHP
 
06 pig-01-intro
06 pig-01-intro06 pig-01-intro
06 pig-01-intro
 
Giraph+Gora in ApacheCon14
Giraph+Gora in ApacheCon14Giraph+Gora in ApacheCon14
Giraph+Gora in ApacheCon14
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
 
apachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdfapachecamelk-april2019-190409093034.pdf
apachecamelk-april2019-190409093034.pdf
 
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
 
scalaphx-akka-http
scalaphx-akka-httpscalaphx-akka-http
scalaphx-akka-http
 
Rango
RangoRango
Rango
 
Design for Scalability in ADAM
Design for Scalability in ADAMDesign for Scalability in ADAM
Design for Scalability in ADAM
 
Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012Introduction to ZooKeeper - TriHUG May 22, 2012
Introduction to ZooKeeper - TriHUG May 22, 2012
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
PHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLitePHP, the GraphQL ecosystem and GraphQLite
PHP, the GraphQL ecosystem and GraphQLite
 
Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2
 

Recently uploaded

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Recently uploaded (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Scalatra 2.2

  • 2. 2   Short  introduc,on   And  overview  of     New  features  
  • 3. What?   ●  Rou5ng   ●  Params   ●  Json4s   ●  Akka   ●  Atmosphere   ●  Commands  
  • 4. Hello,  Scalatra   class  HelloWorld  extends  ScalatraServlet  {          get("/hello/:name")  {          <h1>Hello,  {params("name")}</h1>      }   }  
  • 5. Hello,  Scalatra:  Routes   class  HelloWorld  extends  ScalatraServlet  {          get("/hello/:name")  {          <h1>Hello,  {params("name")}</h1>      }   }   ●  Matches  GET  requests  to  /hello/*   ●  Captures  named  parameters  from  the  route  (here,  :name).   ●  Matching  requests  are  dispatched  to  the  ac5on.  
  • 6. Hello,  Scalatra:  Ac,ons   class  HelloWorld  extends  ScalatraServlet  {          get("/hello/:name")  {          <h1>Hello,  {params("name")}</h1>      }   }   ●  When  a  request  matches  a  route,  the  ac5on  is  run.   ●  A  response  is  generated  from  the  ac5on's  result.   Supports  XML  literals,  Byte  arrays,  Strings,  Files,   InputStreams.   ●  Rendering  of  ac5on  results  is  customizable.  
  • 7. Hello  Scalatra:  ScalatraServlet   class  HelloWorld  extends  ScalatraServlet  {      get("/hello/:name")  {          <h1>Hello,  {params("name")}</h1>      }   }   ●  ScalatraServlet  provides  the  HTTP  DSL.   ●  Scalatra  2.x  is  built  on  Java  Servlets,  the   standard  web  server  API  for  the  JVM.  
  • 8. Why  Scalatra?   ●  Based  on  Sinatra,   •  Java   which  I  like  to  call   •  F#   "the  universal  web   •  Erlang   DSL".    Clones  exist  in:   •  Haskell   •  Ruby   •  Clojure   •  PHP   •  Bash   •  Python   •  Many  others   •  JavaScript  
  • 9. Scalatra  Philosophy   ●  Stateless  by  default,   •  Akka   sessions  if  you  need   •  Atmosphere   them.   •  Embrace  standards   ●  Lean  by  default,   •  HTTP   integra5ons  if  they're   •  JVM   popular.   •  Scala   •  Scalate   •  Beginner  friendly.   •  JSON4s   •  Scale  with  your  app   and  your  exper5se.  
  • 10. Rou,ng  in  depth:  Methods   get("/hello/:name")  {  "Hi,  "+params("name")  }   ●  Routes  start  with  an  HTTP  method.   •  Get  /  Head  /  Op5ons  /  Connect   •  Post  /  Put  /  Patch  /  Delete  /  Trace   ●  Advanced  usage:  can  call  at  any5me  to  register   routes  on  the  fly.  
  • 11. Rou,ng  in  depth:  Params   get("/hello/:name")  {  "Hi,  "+params("name")  }   ●  Matches  the  servlet  path.   •  Pro5p:  compose  large  apps  with  mul5ple  servlets   ●  Declare  route  params  with  a  leading  ':’   •  Matches  everything  up  to  next  '/',  '?',  or  '#'  
  • 12. Rou,ng  in  depth:  Params  
  • 13. Rou,ng  in  depth:  Splats   get("/hello/*")  {  multiParams("splat").mkString(",")  }   ●  Splats get stored in the captures param. ●  If you expect multiple values, you can access it through multiParams. •  params is just a convenient view of multiParams
  • 14. Rou,ng  in  depth:  regex   get("""/hello/(w+)""".r)  {  "Hello,  "+params("captures")  }     ●  Use if you have a real hairy route that standard syntax can't handle. ●  No named groups yet. Java didn't add named regexes until version 7!
  • 15. Rou,ng  in  depth:  booleans   def  userAgent  =  request.getHeader("User-­‐Agent”)   get("/hello/:name",  !userAgent.contains("Lynx"))  {     status  =  403   "You  and  your  fancy,  schmancy  browser.  Get  out.”  }   ●  Both paths and boolean expressions are converted to route matchers. Implicitly ●  A route matches if and only if all route matchers match.
  • 16. Ac,ons  in  depth:  return  value   ●  The return value of an action becomes the body of the response.  
  • 17. •  It's just a •  Override Ac,ons  in  depth:  render  pipeline   protected  def  renderPipeline:  RenderPipeline  =  {      case  bytes:  Array[Byte]  =>          response.outputStream.write(bytes)      case  is:  java.io.InputStream  =>          using(is)  {  util.io.copy(_,  response.outputStream)  }   } ●  It's just a partial function. ●  Override it. Use orElse to delegate to the default.
  • 18. Ac,ons  in  depth:  mutable  
  • 19. Ac,ons  in  depth:  mutable   get("/hello/:name")  {   status  =  HttpServletResponse.SC_GONE     contentType  =  "text/html”   <h1>Goodbye,  cruel  world</h1>  }   ●  Status and headers are typically set in an imperative fashion.   ●  Response is thread local. Relax.
  • 20. Commands   ●  Capture  input   ●  Validate  input  
  • 21. Integra,ons:  JSON4S   ●  Serialize  case  classes  to  json   ●  Handles  xml  as  well  as  json  
  • 22. Integra,ons:  Akka   ●  Takes  advantage  of  servlet  3.0  async  support  
  • 23. Integra,ons:  Atmosphere   ●  WebSocket     ●  Server  side  events   ●  Like  socket.io  but  not  socket.io