Upgrade your Spark REST Server with Akka HTTP & Spark 2.0

Table of contents
Reading Time: 2 minutes

About an year ago, in one of our blog – Spark with Spray Starter Kit we explained about creating REST Services with Spark and Spray. But, from past one year there has not been much development on Spray which tells us that soon Spray will be out-of-phase.

So, we decided to Upgrade our Spark REST Server with Akka HTTP and Spark 2.0. Akka HTTP is a suite of libraries that are used to implement a full server- and client-side HTTP stack on top of akka-actor and akka-stream. It is not a web-framework but rather a more general toolkit for providing and consuming HTTP-based services.

Now, lets take a look at some code. First lets see the dependencies which we are going to need for building our application:

Since, Spark 2.0 is still in preview phase, so we will be using 2.0.0-preview version of Spark.

Next comes a standard template of an Akka HTTP Server, which looks like following in code:

The above code will create and bind a HTTP Server with localhost at port number 8001.

At last we define SparkServices, which contains Spark Service routes:

Now when we are done with coding, lets start the server and test it. So, type in command sbt run on terminal and hit http://localhost:8001/version on any browser. We can see following result on browser:



For complete code of this template click here.

Written by 

Himanshu Gupta is a software architect having more than 9 years of experience. He is always keen to learn new technologies. He not only likes programming languages but Data Analytics too. He has sound knowledge of "Machine Learning" and "Pattern Recognition". He believes that best result comes when everyone works as a team. He likes listening to Coding ,music, watch movies, and read science fiction books in his free time.