Iain Hull

A Simple REST DSL Part 6

A big thank you to everyone who attended my talk at ScalaDays

A big thank you to everyone who attended my talk at ScalaDays. I really enjoyed all your excellent feedback. Here is a blog I was working on before hand. Before talking about testing I would like to cover some changes I made to extractors and assertions. Previously extractors were simple functions, this is an efficient implementation but the test failures result in generic exceptions and the only clue to the cause is a stack trace.

A Simple REST DSL Part 5

Today I want to talk about how I structure my DSL code base.

I haven’t had a chance to write about my REST DSL in ages. So today I want to talk about how I structure my DSL code base. First all functionality is implemented in a simple API. This is a collection of classes and methods defined in the Api object. This has a lot of advantages The full functionality is available to users who do not want to use the DSL. The full functionality can be tested independently of the DSL.

Scaladays Presentation Online

The video of my talk from Scala Days in San Francisco is now online.

The video of my talk from Scala Days in San Francisco is now online. Abstract This talk is aimed at Scala developers with a background in object oriented programming who want to learn new ways to use types to improve the correctness of their code. It introduces the topic in a practical fashion, concentrating on the “easy wins” developers can apply to their code today. View slides online More details and a full set of references are up on the Workday developer blog.

A Simple REST DSL Part 4

Providing a fluid syntax for common request properties.

At the end of part 3 we had a Domain Specific Language (DLS) that could neatly express a complete REST use case. It fully described the requests and their expected responses. val Jason: Person = ??? val personJson = Json.stringify(Jason) val EmptyList = List[Person]() RequestBuilder() url "http://api.rest.org/person" apply { implicit rb => GET asserting (statusCode is Status.OK, jsonBodyAsList[Person] is EmptyList) val id = POST body personJson asserting (statusCode is Status.Created) returning (header("X-Person-Id")) GET / id asserting (statusCode is Status.

A Simple REST DSL Part 3

Processing http responses.

In part 2, I showed how to describe and execute REST requests with a simple descriptive syntax, but it completely ignored processing the response. This should be as simple as making the request. First let’s simplify access to the components of the response. You can create a returning method to execute the Request and extract one or more values from the Response. For example: {% highlight scala %} val personJson = “”"{ “name”: “Jason” }""" RequestBuilder() url “http://api.