-
Notifications
You must be signed in to change notification settings - Fork 65
Route Creation
The RhoService
is the primary method for creating routes. Route creation is performed in the constructor using combinators defined in the rho package object.
/// src_inlined SimplePath core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
The rho DSL defines helpers for creating path, query, and header rules which will match and/or extract data from the Request
. All of these rules can be stored and used in the creation of more complex routes:
/// src_inlined ReusePath core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
Path rules are concerned with defining the path portion of the route. Portions of the path can be matched or captured:
/// src_inlined PathCapture core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
The entire rest of the path can be captured using the *
rule:
/// src_inlined CaptureTail core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
Query rules are captured in essentially the same manner as path rules:
/// src_inlined QueryCapture core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
Of course you can use query capture rules with path capture rules:
/// src_inlined MultiCapture core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
Headers work essentially the same as path and query rules:
/// src_inlined HeaderCapture core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined
Status codes are not necessarily required: rho will accept anything with an EntityEncoder
:
/// src_inlined ResultTypes core/src/test/scala/org/http4s/rhotest/ApiExamples.scala
/// end_src_inlined