What is best way to define http().bindAndHandle

Hi

I need to build a project with akka typed and akka http
so i have some questions:
1- when we use both akka(typed) and akka http , we must create two actorsystem?
2- what is the best way to define http().bindAndHandle? my problem is the defining route part.
in the official akka http quick start guide, for defining route they use this way:

val routes = new UserRoutes(userRegistryActor)(context.system)

do you think this way is good if we have more than 10 route? or want to use swagger?

No, only create a typed ActorSystem. Typed ActorSystems are backed by classic ones and you can always get the classic one using .classicSystem().

If you are starting with Akka HTTP right now, you should use 10.2.0-RC2 which has better support to support typed actor systems. See the example at Routing DSL • Akka HTTP for a general example of how it looks like with the latest version.

If you have many routes, you should create one object/class that defines the “root route”, the root route would look something like this:

val root: Route =
  concat(
    pathPrefix("item")(itemRoutes),
    pathPrefix("customer")(customerRoutes)
  )

where itemRoutes and customerRoutes could be defined in different files.

From you bootstrapping code you can then use

Http().newServerAt(...).bind(RootRoute.root)

to bind a server containing all the given routes. See Routing DSL style guide • Akka HTTP for more guidelines about how to organize routes.

Would that work?

1 Like

thank you. it worked

1 Like