4

I have whole business logic along with its integration to database written in Java. Now I have two options: either I can write a Restful webservice to access it or I can follow the standard servlet approach to access it from UI... What are the advantages and disadvantages of both?

Jayant
  • 323
  • 3
  • 13

3 Answers3

3

In fact, you try to compare things that are different.

REST is a style of architecture targetted distributed systems in the context of the Web technologies. Whereas it doesnt depend on the HTTP protocol, the latter is particularly suitable to implement these concepts. Implementing a RESTful service with HTTP means that we will leverage all its features and use them for the right thing. Those principles can be implemented with different technologies and in Java with different frameworks.

This link could provide you some insights about the REST concepts: https://templth.wordpress.com/2014/12/15/designing-a-web-api/.

Servlets correspond to an API and a container to handle Web applications. The container is responsible of the transport layer and let you focus on the way to handle HTTP requests and create responses. But you are free to them to build you application and use HTTP like you want. Most of time a framework is used on the top of them to implement applications. You can even implement RESTful applications with raw servlets if you want with a bit of additional work.

There are several frameworks like that:

  • Restlet (http://restlet.com/projects/restlet-framework/) that allows to create and / or consume RESTful services in Java. They can be executed in a standalone application or within a servlet container.
  • Spring MVC that provides a support to configure Web applications within lightweight container with dependency injection. The framework also provides REST support.

Hope it helps you, Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
0

Webservice going to help you to communicate between two application which may be having different platform(for example communication between java and .NET possible using this).

But servlet can bind u to talk within one application which is bind with java platform. you can able to talk with two java application using servlet also but for that u have change server configuration. So please understand your requirement and use it

Pankaj Saboo
  • 1,125
  • 1
  • 8
  • 27
0

As Thierry said, they are diferent things, and its up to you define the need of REST implementation. I would suggest an article: http://martinfowler.com/articles/microservices.html

Its a very reusable way to isolate and expose your business logic.

Guilherme
  • 593
  • 1
  • 6
  • 23
  • Microservices is not strictly related to REST, it's a much more deep concept. You can have a monolith application with a REST API. If you implement microservices you would probably use REST because its a ligthweight mechanism for communicate the multiple services but you could also use SOAP. – gabrielgiussi Oct 13 '15 at 19:29
  • Great, indeed!That's why I suggest the article! – Guilherme Oct 14 '15 at 12:47