Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Slides and code samples for talk at Scala Lift-Off London 2011.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 0-slides
Octocat-spinner-32 1-args
Octocat-spinner-32 2-hlists Cleaned up urlEncode/urlDecode; converted some HConses to ::s October 10, 2011
Octocat-spinner-32 3-paths
Octocat-spinner-32 4-routes
Octocat-spinner-32 5-sites
Octocat-spinner-32 6-implicits
Octocat-spinner-32 7-lift-app
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 sbt-launch.jar
README.md

A Route To The Three 'R's: Reading, Writing and the REST

Slides, notes and code samples for my talk at Scala Lift-Off London 2011.

Abstract

The mappings between URLs and code form an integral part of any web application. Many web frameworks help map from URLs to code, but the reverse mapping is often neglected, leaving developers to construct URLs via haphazard string manipulation. Furthermore, many frameworks do not match URLs in a type-safe manner.

Scala provides all the tools we need to address this problem in a more comprehensive manner. In this talk we will walk through the creation of Bigtop Routes, a bidirectional mapping library that is both type-safe and developer-friendly. We will pay particular attention to the ways in which Scala language features, such as flexible syntax, implicit conversions, and a touch of type-level programming, help to simplify the task at hand.

Video and Slides

Skills Matter have posted a video of the talk here:

The slides are available here:

Code

In the talk I build the routes library in stages from the ground up. There is a code sample associated with each stage. In each case I recommend you check out the unit tests to see what's going on, and then invoke the Scala console to play with the code yourself. For example:

bash$ cd 1-args                            # change to the example directory


bash$ ls src/test/scala                    # see what test files there are
ArgSpec.scala


less src/test/scala/ArgSpec.scala          # have a look at the tests to see what's going on
<< file contents appears here >>


./sbt test                                 # run the tests to check it all works
[info] Set current project to 1-args (in build file:/blah/blah/1-args/)
[info]   + IntArg.encode encodes as expected
[info]   + IntArg.decode decodes integers correctly
[info]   + IntArg.decode only decodes integers
[info]   + StringArg.encode does not (un)escape reserved characters
[info]   + StringArg.decode does not (un)escape reserved characters
[info] Passed: : Total 5, Failed 0, Errors 0, Passed 5, Skipped 0
[success] Total time: 4 s, completed Oct 10, 2011 3:54:14 PM


./sbt console                              # start an interactive shell to try it for yourself
[info] Set current project to 1-args (in build file:/blah/blah/1-args/)
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.


scala> IntArg.decode("123")                # run some Scala commands to see what happens
res0: Option[Int] = Some(123)


scala> :quit                               # quit the Scala console

Licence

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Something went wrong with that request. Please try again.