A RESTy-JSON API
with spray.io and maven
sponsored by special appearance
Ignasi Marimon-Clos i Sunyol
@ignasi35
#scalabcn
Sunday, June 16, 13
thanks!
Sunday, June 16, 13
special thank you’s
JPradel (@agile_jordi): review and organization
JCasadellà (@jcasadella): review
JRudolph for simplifying step 4
https://github.com/jrudolph/scala-meetup-spray/commit/
c4991938ec7b26b183d701aac73949e7822cf45e
Sunday, June 16, 13
about me
n. /iŋ'nazi/
1) problem solver, Garbage Collector, mostly
java, learning scala, some agile
2) kayaker
3) under construction
4) wears glasses
Sunday, June 16, 13
what we saw
• BDD (cucumber)
• TDD (scalatest)
• sbt (inifinite run)
• intelliJ
• JAX-RS
• Jetty
https://github.com/funcio/bdd-jaxrs-hands-on
Sunday, June 16, 13
what we’ll see
• BDD (cucumber)
• TDD (scalatest)
• sbt (inifinite run)
• intelliJ
• JAX-RS
• Jetty
• BDD (jbehave?)
• TDD (scalatest)
• mvn (infinite run)
• eclipse (worksheet)
• spray-can/https/...
• spray-json
https://github.com/ignasi35/scala-meetup-spray
Sunday, June 16, 13
why? (1/2)
• I’m comfy with eclipse
• I’m comfy with maven (I know that’s weird)
• (no more)Typesafe delivers a prepacked env
• still there s/where
• eclipse-maven integration is solid
• I needed infinite-test in maven at work
• I like trolling Jordi and Jose
Sunday, June 16, 13
why? (2/2)
• spray.io has akka
• spray 1.x has akka 2.x
• spray.io is modularized (that’s useful)
• I don’t need java API (@see play)
• spray-json is f*&[ing simple (via shapeless)
http://spray.io/project-info/current-versions/
Sunday, June 16, 13
why? (bonus)
• spray.io beats all other JVM stacks/fw (*)
http://www.techempower.com/benchmarks/
Sunday, June 16, 13
spray
modules
provided
provided
There’s more provided dep’s
than those labelled but we don’t
need that level of detail now.
credit: graphic made using yuml.me
http://yuml.me/diagram/scruffy/class/[A]->[B],[A]->[C],[B]->[C]
Sunday, June 16, 13
spray
• One thing done right
• spray-routing => simple entry point.
• @sirthias (Mathias Doenitz) in Akka 2.2
• magnet pattern
• alternate to method overload
• IOBridge, directives, Marshallers, ...???
Sunday, June 16, 13
Sunday, June 16, 13
step 1
• Given an HTTP server
• When I GET /hello
• Then I obtain “hello”
Sunday, June 16, 13
step 1 (tips)
• Edit a web.xml
• Create a mapping
• Provide a BeanConnectionBeanFactory
• Add a servers.xml
• Invoke the Olds Gods and the New
Sunday, June 16, 13
specially dedicated to @ch4lit
Sunday, June 16, 13
step 2
• Given an HTTP server
• When I GET /hello.json
• Then I obtain “{msg:‘world’}”
Sunday, June 16, 13
directives + complete
• path/pathPrefix/pathTest
• authenticate
• get/post/delete/...
• decodeRequest/encodeResponse/...
• cache/alwaysCache/...
• complete
http://spray.io/documentation/spray-routing/predefined-directives-alphabetically/
Sunday, June 16, 13
step 3
• Given an HTTP server
• When I GET /books.json
• Then I obtain the complete books stock
Sunday, June 16, 13
step 4
• Given an HTTP server
• And I POST a book.txt in /books
• When I GET /books.json
• Then I obtain the updated books stock
MEGA-KUDOS to
https://github.com/jrudolph
Sunday, June 16, 13
step 5
• Given an HTTP server
• And a programmatic HTTP client
• When I GET /hello.json
• Then I obtain “{msg:‘world’}”
Sunday, June 16, 13
conclusions
• scala in maven is tough
• mvn plugin lacks infini-run, infini-install,...
• scala worksheet rocks
• spray allows a quick entry point
• docs and examples still to be improved
• because I’m very dumb
• ...
Sunday, June 16, 13
thanks!
Sunday, June 16, 13

Spray & Maven Intro for Scala Barcelona Developers Meetup

  • 1.
    A RESTy-JSON API withspray.io and maven sponsored by special appearance Ignasi Marimon-Clos i Sunyol @ignasi35 #scalabcn Sunday, June 16, 13
  • 2.
  • 3.
    special thank you’s JPradel(@agile_jordi): review and organization JCasadellà (@jcasadella): review JRudolph for simplifying step 4 https://github.com/jrudolph/scala-meetup-spray/commit/ c4991938ec7b26b183d701aac73949e7822cf45e Sunday, June 16, 13
  • 4.
    about me n. /iŋ'nazi/ 1)problem solver, Garbage Collector, mostly java, learning scala, some agile 2) kayaker 3) under construction 4) wears glasses Sunday, June 16, 13
  • 5.
    what we saw •BDD (cucumber) • TDD (scalatest) • sbt (inifinite run) • intelliJ • JAX-RS • Jetty https://github.com/funcio/bdd-jaxrs-hands-on Sunday, June 16, 13
  • 6.
    what we’ll see •BDD (cucumber) • TDD (scalatest) • sbt (inifinite run) • intelliJ • JAX-RS • Jetty • BDD (jbehave?) • TDD (scalatest) • mvn (infinite run) • eclipse (worksheet) • spray-can/https/... • spray-json https://github.com/ignasi35/scala-meetup-spray Sunday, June 16, 13
  • 7.
    why? (1/2) • I’mcomfy with eclipse • I’m comfy with maven (I know that’s weird) • (no more)Typesafe delivers a prepacked env • still there s/where • eclipse-maven integration is solid • I needed infinite-test in maven at work • I like trolling Jordi and Jose Sunday, June 16, 13
  • 8.
    why? (2/2) • spray.iohas akka • spray 1.x has akka 2.x • spray.io is modularized (that’s useful) • I don’t need java API (@see play) • spray-json is f*&[ing simple (via shapeless) http://spray.io/project-info/current-versions/ Sunday, June 16, 13
  • 9.
    why? (bonus) • spray.iobeats all other JVM stacks/fw (*) http://www.techempower.com/benchmarks/ Sunday, June 16, 13
  • 10.
    spray modules provided provided There’s more provideddep’s than those labelled but we don’t need that level of detail now. credit: graphic made using yuml.me http://yuml.me/diagram/scruffy/class/[A]->[B],[A]->[C],[B]->[C] Sunday, June 16, 13
  • 11.
    spray • One thingdone right • spray-routing => simple entry point. • @sirthias (Mathias Doenitz) in Akka 2.2 • magnet pattern • alternate to method overload • IOBridge, directives, Marshallers, ...??? Sunday, June 16, 13
  • 12.
  • 13.
    step 1 • Givenan HTTP server • When I GET /hello • Then I obtain “hello” Sunday, June 16, 13
  • 14.
    step 1 (tips) •Edit a web.xml • Create a mapping • Provide a BeanConnectionBeanFactory • Add a servers.xml • Invoke the Olds Gods and the New Sunday, June 16, 13
  • 15.
    specially dedicated to@ch4lit Sunday, June 16, 13
  • 16.
    step 2 • Givenan HTTP server • When I GET /hello.json • Then I obtain “{msg:‘world’}” Sunday, June 16, 13
  • 17.
    directives + complete •path/pathPrefix/pathTest • authenticate • get/post/delete/... • decodeRequest/encodeResponse/... • cache/alwaysCache/... • complete http://spray.io/documentation/spray-routing/predefined-directives-alphabetically/ Sunday, June 16, 13
  • 18.
    step 3 • Givenan HTTP server • When I GET /books.json • Then I obtain the complete books stock Sunday, June 16, 13
  • 19.
    step 4 • Givenan HTTP server • And I POST a book.txt in /books • When I GET /books.json • Then I obtain the updated books stock MEGA-KUDOS to https://github.com/jrudolph Sunday, June 16, 13
  • 20.
    step 5 • Givenan HTTP server • And a programmatic HTTP client • When I GET /hello.json • Then I obtain “{msg:‘world’}” Sunday, June 16, 13
  • 21.
    conclusions • scala inmaven is tough • mvn plugin lacks infini-run, infini-install,... • scala worksheet rocks • spray allows a quick entry point • docs and examples still to be improved • because I’m very dumb • ... Sunday, June 16, 13
  • 22.