# What is best way to define http().bindAndHandle

**URL:** <https://discuss.akka.io/t/what-is-best-way-to-define-http-bindandhandle/6946>\
**Category:** Akka HTTP\
**Created:** [July 26, 2020, 3:24pm UTC](https://discuss.akka.io/t/what-is-best-way-to-define-http-bindandhandle/6946 "2020-07-26T15:24:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xmoooz](https://avatars.discourse-cdn.com/v4/letter/x/df788c/32.png) [@xmoooz](https://discuss.akka.io/u/xmoooz)\
**Post date:** [July 26, 2020, 3:24pm UTC](https://discuss.akka.io/t/what-is-best-way-to-define-http-bindandhandle/6946/1 "2020-07-26T15:24:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jrudolph](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/jrudolph/32/80_2.png) [@jrudolph](https://discuss.akka.io/u/jrudolph)\
**Post date:** [July 28, 2020, 11:44am UTC](https://discuss.akka.io/t/what-is-best-way-to-define-http-bindandhandle/6946/2 "2020-07-28T11:44:06Z")

</div>

> [@xmoooz](#):
>
> 1- when we use both akka(typed) and akka http , we must create two actorsystem?

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](https://doc.akka.io/docs/akka-http/10.2/routing-dsl/index.html) for a general example of how it looks like with the latest version.

> [@xmoooz](#):
>
> 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?

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

```auto
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

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

```

to bind a server containing all the given routes. See [Routing DSL style guide • Akka HTTP](https://doc.akka.io/docs/akka-http/10.2/routing-dsl/style-guide.html) for more guidelines about how to organize routes.

Would that work?

---

<div class="post-metadata">

**Author:** ![xmoooz](https://avatars.discourse-cdn.com/v4/letter/x/df788c/32.png) [@xmoooz](https://discuss.akka.io/u/xmoooz)\
**Post date:** [July 30, 2020, 2:59pm UTC](https://discuss.akka.io/t/what-is-best-way-to-define-http-bindandhandle/6946/3 "2020-07-30T14:59:47Z")

</div>

> [@jrudolph](#):
>
> Would that work?

thank you. it worked
