O'Reilly logo

RESTful Web Services with Scala by Jos Dirksen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

HTTP verb and URL matching

Unfiltered uses standard Scala pattern matching to determine what to do with a specific request. The following code shows how Unfiltered provides matchers for a number of simple REST calls:

package org.restwithscala.chapter3.steps import unfiltered.request._ import unfiltered.response._ object Step1 extends App { Thread.currentThread().setName("swj"); object api extends unfiltered.filter.Plan { def intent = taskApi.onPass(fallback) def taskApi = unfiltered.filter.Intent { case GET(Path("/tasks")) => ResponseString(s"Get all tasks" ) case GET(Path(Seg("tasks" :: id :: Nil))) => ResponseString(s"Get a single task with id: $id" ) case DELETE(Path(Seg("tasks" :: id :: Nil))) => ResponseString (s"Delete an existing task with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required