Skip to content

Commit

Permalink
Rename RhoService to RhoRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
chuwy committed Oct 29, 2018
1 parent 5f8c926 commit bf440e5
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 99 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/org/http4s/rho/AuthedContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import shapeless.{::, HNil}
import org.http4s.rho.bits.{FailureResponseOps, SuccessResponse, TypedHeader}


/** The [[AuthedContext]] provides a convenient way to define a RhoService
/** The [[AuthedContext]] provides a convenient way to define a RhoRoutes
* which works with http4s authentication middleware.
* {{{
* case class User(name: String, id: UUID)
Expand All @@ -19,7 +19,7 @@ import org.http4s.rho.bits.{FailureResponseOps, SuccessResponse, TypedHeader}
*
* object Auth extends AuthedContext[IO, User]
*
* object BobService extends RhoService[IO] {
* object BobService extends RhoRoutes[IO] {
* GET +? param("foo", "bar") >>> Auth.auth |>> { (foo: String, user: User) =>
* Ok(s"Bob with id ${user.id}, foo $foo")
* }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import shapeless.{HList, HNil}

/** Constructor class for defining routes
*
* The [[RhoService]] provides a convenient way to define routes in a style
* The [[RhoRoutes]] provides a convenient way to define routes in a style
* similar to scalatra etc by providing implicit conversions and an implicit
* [[CompileRoutes]] inside the constructor.
*
* {{{
* val srvc = new RhoService[IO] {
* new RhoRoutes[IO] {
* POST / "foo" / pathVar[Int] +? param[String]("param") |>> { (p1: Int, param: String) =>
* Ok("success")
* }
Expand All @@ -22,10 +22,10 @@ import shapeless.{HList, HNil}
*
* @param routes Routes to prepend before elements in the constructor.
*/
class RhoService[F[_]: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empty)
class RhoRoutes[F[_]: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empty)
extends bits.MethodAliases
with bits.ResponseGeneratorInstances[F]
with RoutePrependable[F, RhoService[F]]
with RoutePrependable[F, RhoRoutes[F]]
with EntityEncoderInstances
with RhoDsl[F]
{
Expand All @@ -35,13 +35,13 @@ class RhoService[F[_]: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empt

final implicit protected def compileService: CompileRoutes[F, RhoRoute.Tpe[F]] = serviceBuilder

/** Create a new [[RhoService]] by appending the routes of the passed [[RhoService]]
/** Create a new [[RhoRoutes]] by appending the routes of the passed [[RhoRoutes]]
*
* @param other [[RhoService]] whos routes are to be appended.
* @return A new [[RhoService]] that contains the routes of the other service appended
* @param other [[RhoRoutes]] whos routes are to be appended.
* @return A new [[RhoRoutes]] that contains the routes of the other service appended
* the the routes contained in this service.
*/
final def and(other: RhoService[F]): RhoService[F] = new RhoService(this.getRoutes ++ other.getRoutes)
final def and(other: RhoRoutes[F]): RhoRoutes[F] = new RhoRoutes(this.getRoutes ++ other.getRoutes)

/** Get a snapshot of the collection of [[RhoRoute]]'s accumulated so far */
final def getRoutes: Seq[RhoRoute[F, _ <: HList]] = serviceBuilder.routes()
Expand All @@ -50,9 +50,9 @@ class RhoService[F[_]: Monad](routes: Seq[RhoRoute[F, _ <: HList]] = Vector.empt
final def toRoutes(middleware: RhoMiddleware[F] = identity): HttpRoutes[F] =
serviceBuilder.toRoutes(middleware)

final override def toString: String = s"RhoService(${serviceBuilder.routes().toString()})"
final override def toString: String = s"RhoRoutes(${serviceBuilder.routes().toString()})"

final override def /:(prefix: TypedPath[F, HNil]): RhoService[F] = {
new RhoService(serviceBuilder.routes().map { prefix /: _ })
final override def /:(prefix: TypedPath[F, HNil]): RhoRoutes[F] = {
new RhoRoutes(serviceBuilder.routes().map { prefix /: _ })
}
}
30 changes: 15 additions & 15 deletions core/src/test/scala/ApiExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.time.Instant
import java.util.concurrent.atomic.AtomicInteger

import org.http4s.headers.{ETag, `Content-Length`}
import org.http4s.rho.RhoService
import org.http4s.rho.RhoRoutes
import org.http4s.rho.bits.TypedQuery
import org.http4s.server.websocket.WebSocketBuilder
import org.http4s.{Request, UrlForm}
Expand All @@ -18,13 +18,13 @@ class ApiExamples extends Specification {
"Make it easy to compose routes" in {

/// src_inlined SimplePath
new RhoService[IO] {
new RhoRoutes[IO] {
GET / "hello" |>> { () => Ok("Hello, world!") }
}
/// end_src_inlined

/// src_inlined ReusePath
new RhoService[IO] {
new RhoRoutes[IO] {
// A path can be built up in multiple steps and the parts reused
val pathPart1 = GET / "hello"

Expand All @@ -34,7 +34,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined PathCapture
new RhoService[IO] {
new RhoRoutes[IO] {
// Use combinators to parse and capture path parameters
GET / "helloworldnumber" / pathVar[Int] / "foo" |>> { i: Int =>
Ok("Received $i")
Expand All @@ -59,7 +59,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined CaptureTail
new RhoService[IO] {
new RhoRoutes[IO] {
// You can capture the entire rest of the tail using *
GET / "hello" / * |>> { r: List[String] =>
Ok(s"Got the rest: ${r.mkString}")
Expand All @@ -68,7 +68,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined QueryCapture
new RhoService[IO] {
new RhoRoutes[IO] {
// Query parameters can be captured in a similar manner as path fragments
GET / "hello" +? param[Int]("fav") |>> { i: Int =>
Ok(s"Query 'fav' had Int value $i")
Expand All @@ -77,7 +77,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined MultiCapture
new RhoService[IO] {
new RhoRoutes[IO] {
// A Path can be made all at once
POST / pathVar[Int] +? param[Int]("fav") |>> { (i1: Int, i2: Int) =>
Ok(s"Sum of the number is ${i1 + i2}")
Expand All @@ -86,15 +86,15 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined HeaderCapture
new RhoService[IO] {
new RhoRoutes[IO] {
GET / "hello" >>> capture(ETag) |>> { tag: ETag =>
Ok(s"Thanks for the tag: $tag")
}
}
/// end_src_inlined

/// src_inlined HeaderRuleCombine
new RhoService[IO] {
new RhoRoutes[IO] {
// Header rules are composable
val ensureLength = existsAnd(`Content-Length`)(_.length > 0)
val getTag = capture(ETag)
Expand All @@ -106,7 +106,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined BooleanOperators
new RhoService[IO] {
new RhoRoutes[IO] {
/*
* Boolean logic
* Just as you can perform 'and' operations which have the effect of
Expand All @@ -127,7 +127,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined RequestAccess
new RhoService[IO] {
new RhoRoutes[IO] {
/* Access the `Request` by making it the first param of the
handler function.
*/
Expand All @@ -141,7 +141,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined ResultTypes
new RhoService[IO] {
new RhoRoutes[IO] {
private val counter = new AtomicInteger(0)
private def getCount(): String = counter.incrementAndGet().toString
// Don't want status codes? Anything with an `EntityEncoder` will work.
Expand All @@ -162,7 +162,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined StatusCodes
new RhoService[IO] {
new RhoRoutes[IO] {
GET / "twoResults" |>> { () =>
if (true) Ok("bytes result".getBytes())
else NotFound("Boo... Not found...")
Expand All @@ -171,7 +171,7 @@ class ApiExamples extends Specification {
/// end_src_inlined

/// src_inlined Decoders
new RhoService[IO] {
new RhoRoutes[IO] {
// Using decoders you can parse the body as well
POST / "postSomething" ^ UrlForm.entityDecoder[IO] |>> { m: UrlForm =>
Ok(s"You posted these things: $m")
Expand All @@ -181,7 +181,7 @@ class ApiExamples extends Specification {

/// src_inlined Composed parameters

new RhoService[IO] {
new RhoRoutes[IO] {
import shapeless.{::, HNil}
case class Foo(i: Int, v: String, a: Double)

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/org/http4s/rho/ApiTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ApiTest extends Specification {
object ruleExecutor extends RuleExecutor[IO]

def runWith[F[_]: Monad, T <: HList, FU](exec: RouteExecutable[F, T])(f: FU)(implicit hltf: HListToFunc[F, T, FU]): Request[F] => OptionT[F, Response[F]] = {
val srvc = new RhoService[F] { exec |>> f }.toRoutes()
val srvc = new RhoRoutes[F] { exec |>> f }.toRoutes()
srvc.apply(_: Request[F])
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/http4s/rho/AuthedContextSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Auth {

object MyAuth extends AuthedContext[IO, User]

object MyService extends RhoService[IO] {
object MyRoutes extends RhoRoutes[IO] {
import MyAuth._

GET +? param("foo", "bar") >>> auth |>> { (_: Request[IO], foo: String, user: User) =>
Expand All @@ -46,7 +46,7 @@ object MyService extends RhoService[IO] {

class AuthedContextSpec extends Specification {

val routes = Auth.authenticated(MyAuth.toService(MyService.toRoutes()))
val routes = Auth.authenticated(MyAuth.toService(MyRoutes.toRoutes()))

"AuthedContext execution" should {

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/http4s/rho/CodecRouterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class CodecRouterSpec extends Specification {
(rbody, resp.status)
}

"A CodecRouter in a RhoService" should {
"A CodecRouter in a RhoRoutes" should {

val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
(POST / "foo" decoding(EntityDecoder.text[IO])) |>> { s: String => Ok(s"Received: $s") }
(POST / "form" decoding(UrlForm.entityDecoder[IO])) |>> { m: UrlForm => Ok("success") }
}.toRoutes()
Expand Down
28 changes: 14 additions & 14 deletions core/src/test/scala/org/http4s/rho/ParamDefaultValueSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ParamDefaultValueSpec extends Specification {
Request(bits.MethodAliases.GET, Uri.fromString(s).right.getOrElse(sys.error("Failed.")), headers = Headers(h: _*))

"GET /test1" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test1" +? param[String]("param1") |>> { param1: String => Ok("test1:" + param1) }
}.toRoutes()

Expand All @@ -32,7 +32,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test2" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test2" +? param[String]("param1", "default1") |>> { param1: String => Ok("test2:" + param1) }
}.toRoutes()

Expand All @@ -52,7 +52,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test3" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test3" +? param[Int]("param1", 1) |>> { param1: Int => Ok("test3:" + param1) }
}.toRoutes()

Expand All @@ -75,7 +75,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test4" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test4" +? param[Option[String]]("param1") |>> { os: Option[String] => Ok("test4:" + os.getOrElse("")) }
}.toRoutes()

Expand All @@ -95,7 +95,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test5" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test5" +? param[Option[Int]]("param1", Some(100)) |>> { os: Option[Int] => Ok("test5:" + os.getOrElse("")) }
}.toRoutes()

Expand All @@ -118,7 +118,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test6" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test6" +? param[Option[String]]("param1", Some("default1")) |>> { os: Option[String] => Ok("test6:" + os.getOrElse("")) }
}.toRoutes()

Expand All @@ -138,7 +138,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test7" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test7" +? param[Seq[String]]("param1", Seq("a", "b")) |>> { os: Seq[String] => Ok("test7:" + os.mkString(",")) }
}.toRoutes()

Expand All @@ -161,7 +161,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test8" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test8" +? param[Seq[Int]]("param1", Seq(3, 5, 8)) |>> { os: Seq[Int] => Ok("test8:" + os.mkString(",")) }
}.toRoutes()

Expand Down Expand Up @@ -190,7 +190,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test9" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test9" +? param("param1", "default1", (p: String) => !p.isEmpty && p != "fail") |>> { param1: String => Ok("test9:" + param1) }
}.toRoutes()

Expand All @@ -213,7 +213,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test10" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test10" +? param[Int]("param1", 1, (p: Int) => p >= 0) |>> { param1: Int => Ok("test10:" + param1) }
}.toRoutes()

Expand All @@ -239,7 +239,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test11" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test11" +? param[Option[Int]]("param1", Some(100), (p: Option[Int]) => p != Some(0)) |>> { os: Option[Int] => Ok("test11:" + os.getOrElse("")) }
}.toRoutes()

Expand All @@ -265,7 +265,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test12" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test12" +? param[Option[String]]("param1", Some("default1"), (p: Option[String]) => p != Some("fail") && p != Some("")) |>> { os: Option[String] => Ok("test12:" + os.getOrElse("")) }
}.toRoutes()

Expand All @@ -288,7 +288,7 @@ class ParamDefaultValueSpec extends Specification {
}

"GET /test13" should {
val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test13" +? param[Seq[String]]("param1", Seq("a", "b"), (p: Seq[String]) => !p.contains("") && !p.contains("z")) |>> { os: Seq[String] => Ok("test13:" + os.mkString(",")) }
}.toRoutes()

Expand All @@ -315,7 +315,7 @@ class ParamDefaultValueSpec extends Specification {

"GET /test14" should {

val routes = new RhoService[IO] {
val routes = new RhoRoutes[IO] {
GET / "test14" +? param[Seq[Int]]("param1", Seq(3, 5, 8), (p: Seq[Int]) => p != Seq(8, 5, 3)) |>> { os: Seq[Int] => Ok("test14:" + os.mkString(",")) }
}.toRoutes()

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/scala/org/http4s/rho/RequestRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cats.effect.IO
import org.http4s._
import org.http4s.HttpRoutes

/** Helper for collecting a the body from a `RhoService` */
/** Helper for collecting a the body from a `RhoRoutes` */
trait RequestRunner {

def httpRoutes: HttpRoutes[IO]
Expand Down
Loading

0 comments on commit bf440e5

Please sign in to comment.