Clarification around the concept of Path, Mount Point and Prefix in http4s

188 Views Asked by At

I'm trying to clarify some concept that confuse me slightly around http4s path.

Quoting the documentation,

Path info

Path matching is done on the request’s pathInfo. Path info is the request’s URI’s path after the following:

  • the mount point of the service
  • the prefix, if the service is composed with a Router
  • the prefix, if the service is rewritten with TranslateUri

Matching on request.pathInfo instead of request.uri.path allows multiple services to be composed without rewriting all the path matchers.

I would like to clarify the notion of mount point and prefix.

  1. Can some give an example of a mount point definition vs a prefix ?
  2. Can a service have both a mount point and prefix that are not the same ?

I suspect that the mount point in this example is /hello?

HttpRoutes.of[IO] {
        case GET -> Root / "hello" => Ok("hello")
}
  1. When writing the below code, we are defining 2 prefixes / and /api, but are they also consider mount point ?
val services = tweetService <+> helloWorldService

val httpApp  = Router("/" -> helloWorldService, "/api" -> services).orNotFound

Because quoting the documentation, we have:

We start from a BlazeServerBuilder, and then mount the helloWorldService under the base path of / and the remainder of the services under the base path of /api

  1. For the second prefix /api, what is the Root of the helloWorldService in
case GET -> Root / "hello"

is it /api, as in Root = /api ?

  1. What is the mount point of the helloWorldService in that circumstance and what is the prefix ?
0

There are 0 best solutions below