How to combine two HttpService in http4s 0.15.16 #6994
Answered
by
armanbilge
sujit-baniya
asked this question in
Q&A
-
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 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
} |
Beta Was this translation helpful? Give feedback.
Answered by
armanbilge
Feb 23, 2023
Replies: 1 comment 2 replies
-
I found some old docs here: https://http4s.org/v0.15/service/index.html#running-your-service It looks like it still works with |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sujit-baniya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found some old docs here: https://http4s.org/v0.15/service/index.html#running-your-service
It looks like it still works with
orElse
. Maybe you are missingimport org.http4s.server.syntax._
?