Akka HTTP Routing

Knoldus Blogs

In this blog, I try to describe some basic routes of Akka-HTTP, redirection of the route and how to handle extra parameters that come in route.

so before writing the routes, you have to set the environment for it.

implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher

These are the variables that are you need to define provisionally before writing the routes.

so now let’s writing the route –

val route =
      path("hello") {
        get {
          complete("Say hello to akka-http")

now you have to bind this route to a port

val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

Here we define simplest route “/hello”  and whatever response you want to return you have to give into complete() method.
and we bind this route to the localhost:8080.

so let’s move another type of rote –

If you want to send some segment in the…

View original post 360 more words


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s