0

I have a legacy product that's using http4s 0.8 version. I'm trying to do an incremental upgrade and the best version I could upgrade is 0.15.16.

Currently I could use following syntax

service1 orElse service2 orElse

But in 0.15.16 orElse is not available and I'm not sure how could I concat multiple http service.

Code sample


object Test {
    val db = MySQLAdapter(url = "jdbc:mysql:///test?useSSL=false", user = "service", password = "")
    val userDao = UserDao(db)
}

object HealthApi extends ResponseCodec with BooleanCodec {
    
    def service =
        HttpService {
            case GET -> Root / "ping" => true
        }
    
}
object Main extends ServerApp with ResponseCodec with TimestampCodec {
    def service: HttpService = HttpService {
        case GET -> Root / "hello" / name => s"Hello $name"
        case GET -> Root / "user" => Test.userDao.testUser("admin@exam.com")
    }
    def server(args: List[String]): Task[Server] =
        BlazeBuilder
            .withNio2(true)
            .bindHttp(8080)
            .mountService(service, "/api")
            .start
}

FYI: How to combine AuthedRoutes and HttpRoutes in http4s? didn't help

Sujit Baniya
  • 43
  • 1
  • 5

1 Answers1

1

Taken from the changelog it is mentioned to be replaced with

service |+| anotherService

The full excerpt states [1]

Eliminate Fallthrough typeclass. An HttpService now returns MaybeResponse, which can be a Response or Pass. There is a Semigroup[MaybeResponse] instance that allows HttpServices to be chained as a semigroup. service orElse anotherService is deprecated in favor of service |+| anotherService.

HTH

[1] https://http4s.org/changelog.html#v0-16-0-m1-2017-04-08

swinkler
  • 1,703
  • 10
  • 20