Skip to content
GitWiki edited this page Nov 30, 2015 · 13 revisions

The RhoService

The RhoService is the primary method for creating routes. Route creation is performed in the constructor using combinators defined in the rho package object.

Combinators

The rho DSL defines helpers for creating path, query, and header rules which will match and/or extract data from the Request.

Path rules

Path rules are concerned with defining the path portion of the route. Rules can be simple matching rules:

/// src_inlined SimplePath core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
      new RhoService {
        GET / "hello" |>> { () => Ok("Hello, world!") }
      }
/// end_src_inlined

or they can capture data from a path segment:

/// src_inlined PathCapture core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
      new RhoService {
        // A Path can be made all at once
        POST / "hello" / pathVar[Int] +? param[Int]("fav") |>> { (i1: Int, i2: Int) =>
          Ok(s"Sum of the number is ${i1 + i2}")
        }
      }
/// end_src_inlined
Clone this wiki locally