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 384 more words

Author: Piyush Rana

Piyush Rana is a Technology Head In, Canada having big data experience of more than 8+ years. He is familiar with Object-Oriented Programming Paradigms and has been working with functional programming for the past 5+ years. He has been handling Big Data and has exposure to technologies like Scala, Spark, Cassandra, Kafka, and dev-Ops-related tools and technologies like Docker and DOCS/Mesos. He is an author of book called - "Programming In Scala: A Practical Step by Step Approach for Functional programming (Knoldus Programming Series)". His hobbies include gaming (the strategy-based, FPS, and role-playing), watching web series, and listening to songs.

Leave a comment