SlideShare uma empresa Scribd logo
1 de 27
Unfiltered
Unveiled
  THE UNFRAMEWORK
Whoami
Code / train Scala for a living
Lately for a NYC startup
Using Unfiltered


Currently freelancer
Former Xebia
Former TomTom
Former Sun Microstems
Former ...
HTTP
    →
GET / HTTP/1.1
Host: nxt.flotsam.nl
                           ←
                      HTTP/1.1 200 OK
                      Date: Mon, 29 Oct 2012
                      …
                      Last-Modified: Wed, 17
Accept: text/html     …
                      ETag:
                      "4ce43eb8b40a4f…"
                      Content-Type: text/html
                      Content-Length: 9636
                      Server: AmazonS3
Frameworks
Solve many
problems around
given domain
Frameworks
Simple problems ☹
Toolkit



Loosely coupled
components that can be
composed to solve           Simple problems ☺
different problems          Complex problems ☺
HTTP

Stuff   Stuff
HTTP

Request   Response
Web Appl.
Request Response
Request’ Response’
Request’’ Response’’
Request’’’ Response’’’
That rings a bell
 … match {
  case … =>   …
  case … =>   …
  case … =>   …
  case … =>   …
Pattern matching
 obj match {
   case i: Int => i * 2
   case s: String => s + s
 }
Partial Function
 {
     case   …   =>   …
     case   …   =>   …
     case   …   =>   …
     case   …   =>   …
Example
val duplicate: PartialFunction[Any,Any] = {
  case s: String => s + s
  case i: Int => i * 2
}

duplicate(3)    // 6
duplicate("yuk") // "yukyuk”
duplicate(4.3) // MatchError
Unfiltered
{                                         Intent
    case _ => ResponseString(“yay”)
}



    GET / HTTP/           HTTP/1.1 200 OK
                          Content-Length: 3
Hitting the road
 import unfiltered.filter._
 import unfiltered.jetty._
 import unfiltered.response._

 Http(8090).filter(Planify {
   case _ => ResponseString("Ok")
 }).run
ResponseFunction ①
 case … => …
 case … => … ~> … ~> …



 Ok                  Html(…)
 NotFound            Html5(…)
 ResponseString(…)   JsonContent
 Json(…)             TextXmlContent
 ResponseWriter(…)   Redirect(…)
ResponseFunction ②
 Ok ~> PlainTextContent ~> ResponseString("foo")


 Ok→                      resp.setStatus(SC_OK)

 PlainTextContent→        resp.setContextType("text/plain")

 RepsonseString("foo")→   resp.setCharacterEncoding("UTF-8")
                          val writer = resp.getWriter()
                          writer.print("foo")
                          writer.close
ResponseFunction ③
 Ok ~> PlainTextContent ~> ResponseString("foo")

 NotFound ~> HtmlContent ~> Html(<html>
  <body>Not found</body>
 </html>)

 Redirect("/index.html")
Scalate
             Templates for Scala

                                               SSP
<% val decks: List[Decks] %>                   SCAML
<html>
<body>
                                               Mustache
<ul>                                           …
<% for (deck <- decks) { %>
<li><%= deck.name%></li>
<% } %>                       -@ val decks: List[Decks]
</ul>                         %html
</body>      <html>            %body
</html>      <body>             %ul
             <ul>                - for (deck <- decks)
             {{#decks}}           %li= deck.name
             <li>{{name}}</li>
             {{/decks}}
SCAML
                   In a Nutshell


!!!              <!DOCTYPE html PUBLIC "-//…
%html               <html>
  %body              <body>
    .masthead         <div class="masthead"/>
    #main           <div id="main"/>
    %p(onclick="") YES <p onclick="">YES</p>
    :javascript      <script language="javascript"/>
    :markdown
      *Nice*        <p><em>Nice</em></p>
                 </body>
                 </html>
Extractors ①
      case … => …
      case … & … & … => …


GET(…)            Accept(…)
POST(…)           UserAgent(…)
DELETE(…)         Host(…)
PUT(…)            IfModifiedSince(…)
Path(…)           Referer(…)
Extractors ②
case GET(_)

case GET(Path(path))

case Path(Seg("give","me",something :: Nil))
(Matches "/give/me/money", setting something to "money".)


case Path("/") & Params(params)

case Accept("application/json")
Extractors ③
HttpRequest[A] → { case … => … }


object DotJson {
  unapply[A](req: HttpRequest[A]) =
   req.uri.endsWith(".json")
}

case DotJson() => ResponseString("Json!")
QParams ☣
              MONAD ALERT

import unfiltered.request.QParams._
case req @ Params(params) =>
 val expected = for {
   lat <- lookup("lat") is required("missing")
   lon <- lookup("lon") is required("missing")
 } yield {
   Ok ~>
   PlainTextContent ~>
   ResponseString("%s, %s".format(lat.get, lon.get))
 }
 expected(params) orFail { failures =>
   BadRequest ~> ResponseString(failures.mkString)
But wait,
       there's more


-   OAuth
-   Secure switch          -   Upload
-   Routing kit            -   Netty binding
-   Basic authentication   -   Web Sockets
Key takeaways
Simple ☺
Retain control   ☺
Used for real apps   ☺
Hit the ground running ☺
Encode your own policies ☺
The source code is the documentation ⚇
Typesafe & extensible ☺☺☺
Vibe ☹
Questions?




fl
    Wilfred Springer
    wilfred@flotsam.nl
    http://nxt.flotsam.nl/

Mais conteúdo relacionado

Mais procurados

Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
Thomas Weinert
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
Felinx Lee
 
Template Haskell Tutorial
Template Haskell TutorialTemplate Haskell Tutorial
Template Haskell Tutorial
kizzx2
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
Kang-min Liu
 

Mais procurados (20)

Presentation on php string function part-1
Presentation on php string function part-1Presentation on php string function part-1
Presentation on php string function part-1
 
Solr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg DonovanSolr & Lucene @ Etsy by Gregg Donovan
Solr & Lucene @ Etsy by Gregg Donovan
 
groovy & grails - lecture 2
groovy & grails - lecture 2groovy & grails - lecture 2
groovy & grails - lecture 2
 
Presentation on php string function part-2
Presentation on php string function part-2Presentation on php string function part-2
Presentation on php string function part-2
 
Quebec pdo
Quebec pdoQuebec pdo
Quebec pdo
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
用Tornado开发RESTful API运用
用Tornado开发RESTful API运用用Tornado开发RESTful API运用
用Tornado开发RESTful API运用
 
New in cakephp3
New in cakephp3New in cakephp3
New in cakephp3
 
The promise of asynchronous php
The promise of asynchronous phpThe promise of asynchronous php
The promise of asynchronous php
 
Real time server
Real time serverReal time server
Real time server
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
Living with garbage
Living with garbageLiving with garbage
Living with garbage
 
Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Synta...
Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Synta...Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Synta...
Haste (Same Language, Multiple Platforms) and Tagless Final Style (Same Synta...
 
The Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's PerspectiveThe Browser Environment - A Systems Programmer's Perspective
The Browser Environment - A Systems Programmer's Perspective
 
Template Haskell Tutorial
Template Haskell TutorialTemplate Haskell Tutorial
Template Haskell Tutorial
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 

Destaque

Двумерное моделирование и детали для роботов
Двумерное моделирование и детали для роботовДвумерное моделирование и детали для роботов
Двумерное моделирование и детали для роботов
Anton Moiseev
 

Destaque (7)

Поиск экспортных ниш в образовательной робототехнике
Поиск экспортных ниш в образовательной робототехникеПоиск экспортных ниш в образовательной робототехнике
Поиск экспортных ниш в образовательной робототехнике
 
Двумерное моделирование и детали для роботов
Двумерное моделирование и детали для роботовДвумерное моделирование и детали для роботов
Двумерное моделирование и детали для роботов
 
Как бы нам тоже делать роботов
Как бы нам тоже делать роботовКак бы нам тоже делать роботов
Как бы нам тоже делать роботов
 
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code baseSingle Sourcing RAP and RCP - Desktop and web clients from a single code base
Single Sourcing RAP and RCP - Desktop and web clients from a single code base
 
Популярная робототехника и 3д-печать
Популярная робототехника и 3д-печатьПопулярная робототехника и 3д-печать
Популярная робототехника и 3д-печать
 
Очереди и блокировки. Теория и практика / Александр Календарев (ad1.ru)
Очереди и блокировки. Теория и практика / Александр Календарев (ad1.ru)Очереди и блокировки. Теория и практика / Александр Календарев (ad1.ru)
Очереди и блокировки. Теория и практика / Александр Календарев (ad1.ru)
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 

Semelhante a Unfiltered Unveiled

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
Vaclav Pech
 
Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11
Goro Fuji
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
Adam Lu
 

Semelhante a Unfiltered Unveiled (20)

And the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack SupportAnd the Greatest of These Is ... Rack Support
And the Greatest of These Is ... Rack Support
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
お題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part Aお題でGroovyプログラミング: Part A
お題でGroovyプログラミング: Part A
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
JavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talkJavaScript Neednt Hurt - JavaBin talk
JavaScript Neednt Hurt - JavaBin talk
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Type safe embedded domain-specific languages
Type safe embedded domain-specific languagesType safe embedded domain-specific languages
Type safe embedded domain-specific languages
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Tools for Making Machine Learning more Reactive
Tools for Making Machine Learning more ReactiveTools for Making Machine Learning more Reactive
Tools for Making Machine Learning more Reactive
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11Xslate sv perl-2013-7-11
Xslate sv perl-2013-7-11
 
Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
 
Introduction to Prototype JS Framework
Introduction to Prototype JS FrameworkIntroduction to Prototype JS Framework
Introduction to Prototype JS Framework
 

Mais de Wilfred Springer (13)

Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
Scala in your organisation
Scala in your organisationScala in your organisation
Scala in your organisation
 
Simplicity
SimplicitySimplicity
Simplicity
 
Mongo
MongoMongo
Mongo
 
NoSQL
NoSQLNoSQL
NoSQL
 
NoSQL Rollercoaster
NoSQL RollercoasterNoSQL Rollercoaster
NoSQL Rollercoaster
 
Byzantine Generals
Byzantine GeneralsByzantine Generals
Byzantine Generals
 
Eventually Consistent
Eventually ConsistentEventually Consistent
Eventually Consistent
 
Into the Wild
Into the WildInto the Wild
Into the Wild
 
OOPSLA Talk on Preon
OOPSLA Talk on PreonOOPSLA Talk on Preon
OOPSLA Talk on Preon
 
Spring ME JavaOne
Spring ME JavaOneSpring ME JavaOne
Spring ME JavaOne
 
Spring ME
Spring MESpring ME
Spring ME
 
Preon (J-Fall 2008)
Preon (J-Fall 2008)Preon (J-Fall 2008)
Preon (J-Fall 2008)
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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...
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 

Unfiltered Unveiled

  • 2. Whoami Code / train Scala for a living Lately for a NYC startup Using Unfiltered Currently freelancer Former Xebia Former TomTom Former Sun Microstems Former ...
  • 3. HTTP → GET / HTTP/1.1 Host: nxt.flotsam.nl ← HTTP/1.1 200 OK Date: Mon, 29 Oct 2012 … Last-Modified: Wed, 17 Accept: text/html … ETag: "4ce43eb8b40a4f…" Content-Type: text/html Content-Length: 9636 Server: AmazonS3
  • 6. Toolkit Loosely coupled components that can be composed to solve Simple problems ☺ different problems Complex problems ☺
  • 7. HTTP Stuff Stuff
  • 8. HTTP Request Response
  • 9. Web Appl. Request Response Request’ Response’ Request’’ Response’’ Request’’’ Response’’’
  • 10. That rings a bell … match { case … => … case … => … case … => … case … => …
  • 11. Pattern matching obj match { case i: Int => i * 2 case s: String => s + s }
  • 12. Partial Function { case … => … case … => … case … => … case … => …
  • 13. Example val duplicate: PartialFunction[Any,Any] = { case s: String => s + s case i: Int => i * 2 } duplicate(3) // 6 duplicate("yuk") // "yukyuk” duplicate(4.3) // MatchError
  • 14. Unfiltered { Intent case _ => ResponseString(“yay”) } GET / HTTP/ HTTP/1.1 200 OK Content-Length: 3
  • 15. Hitting the road import unfiltered.filter._ import unfiltered.jetty._ import unfiltered.response._ Http(8090).filter(Planify { case _ => ResponseString("Ok") }).run
  • 16. ResponseFunction ① case … => … case … => … ~> … ~> … Ok Html(…) NotFound Html5(…) ResponseString(…) JsonContent Json(…) TextXmlContent ResponseWriter(…) Redirect(…)
  • 17. ResponseFunction ② Ok ~> PlainTextContent ~> ResponseString("foo") Ok→ resp.setStatus(SC_OK) PlainTextContent→ resp.setContextType("text/plain") RepsonseString("foo")→ resp.setCharacterEncoding("UTF-8") val writer = resp.getWriter() writer.print("foo") writer.close
  • 18. ResponseFunction ③ Ok ~> PlainTextContent ~> ResponseString("foo") NotFound ~> HtmlContent ~> Html(<html> <body>Not found</body> </html>) Redirect("/index.html")
  • 19. Scalate Templates for Scala SSP <% val decks: List[Decks] %> SCAML <html> <body> Mustache <ul> … <% for (deck <- decks) { %> <li><%= deck.name%></li> <% } %> -@ val decks: List[Decks] </ul> %html </body> <html> %body </html> <body> %ul <ul> - for (deck <- decks) {{#decks}} %li= deck.name <li>{{name}}</li> {{/decks}}
  • 20. SCAML In a Nutshell !!! <!DOCTYPE html PUBLIC "-//… %html <html> %body <body> .masthead <div class="masthead"/> #main <div id="main"/> %p(onclick="") YES <p onclick="">YES</p> :javascript <script language="javascript"/> :markdown *Nice* <p><em>Nice</em></p> </body> </html>
  • 21. Extractors ① case … => … case … & … & … => … GET(…) Accept(…) POST(…) UserAgent(…) DELETE(…) Host(…) PUT(…) IfModifiedSince(…) Path(…) Referer(…)
  • 22. Extractors ② case GET(_) case GET(Path(path)) case Path(Seg("give","me",something :: Nil)) (Matches "/give/me/money", setting something to "money".) case Path("/") & Params(params) case Accept("application/json")
  • 23. Extractors ③ HttpRequest[A] → { case … => … } object DotJson { unapply[A](req: HttpRequest[A]) = req.uri.endsWith(".json") } case DotJson() => ResponseString("Json!")
  • 24. QParams ☣ MONAD ALERT import unfiltered.request.QParams._ case req @ Params(params) => val expected = for { lat <- lookup("lat") is required("missing") lon <- lookup("lon") is required("missing") } yield { Ok ~> PlainTextContent ~> ResponseString("%s, %s".format(lat.get, lon.get)) } expected(params) orFail { failures => BadRequest ~> ResponseString(failures.mkString)
  • 25. But wait, there's more - OAuth - Secure switch - Upload - Routing kit - Netty binding - Basic authentication - Web Sockets
  • 26. Key takeaways Simple ☺ Retain control ☺ Used for real apps ☺ Hit the ground running ☺ Encode your own policies ☺ The source code is the documentation ⚇ Typesafe & extensible ☺☺☺ Vibe ☹
  • 27. Questions? fl Wilfred Springer wilfred@flotsam.nl http://nxt.flotsam.nl/

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n