Build Restful service with Java 8 in Five minutes

This is a very basic tutorial for beginners who would like to experiment with Java 8 and Spark Framework.

Sometimes we can complex issues in our head more then it is, I was just trying to teach myself a way to make a simple Java Restful Api to handle few open and simple calls for me. I will share with you my start point.

We will use Intellij and create simple RestApi, basically if you have eclipse it is the same idea.

First lets create the project.
Open Intellij => Choose Maven project
Choose maven-archetype-quickstart
Click Next

#You can choose whatever you wish in the groupid and artifactid
ArtifactId: simplejavarestapi
Click Next


#You can choose your own project name
Project name: simplejavarestapi



The project should open as the following:


In the pom.xml we need to add dependecies, under depencies lets add:

We are done with our configuration, lets start with adding our code.

Spark uses an interface called ResponseTransformer to convert objects returned by routes to an actual HTTP response.this transfomer will route transforming output to JSON using Gson:


Lets create an pojo object that we will use in our code.

In lets add the lines.

Right click on and click on Run ‘App.main()’

Open the browser and go to http://localhost:4567/greeting

GET: http://localhost:4567/greeting


POST: http://localhost:4567/greeting?name=Gabriel


PUT: http://localhost:4567/greeting?name=Gabriel


DELETE: http://localhost:4567/greeting?name=Gabriel


Download project from Github:

Build Restful service with Java 8 in Five minutes
Gabriel Ajabahian
Software Engineer Freelance
I am a Freelance consultant, I’m passionate about creating dynamic applications. With 10+ years technical experience as well as working on major application systems for top down.

I have extensive software engineering experience, recently I focus on Scala/Java and JavaScript. On the other hand, I have experience with C# and .net framework/core. I focus on integrating applications that are built against different frameworks and can run on different platforms.

Scalability, efficiency and performance are key topics for any software, that’s why I keep track of the newest technologies, I never underestimate the power of the cloud, that’s why I do believe in using this power with “edge applications” to expand software’s and solutions to a new level.

Being a software engineer who understand the business as well as my team, looking at things from different perspectives. Being open and honest and investing in relationship makes a big difference.

Specialties: Software development, Scrum/Agile, Process and Problem management.