Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why should anyone take REST ?  RSS feed

 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the burning question in my mind and i am not getting satisfied with the following query.

Query : We know that Servlets can also return JSON and XML apart from the HTML page then why should one use the other technology like REST, why not use the available solutions like Servlets technology.


I am sure after replies , i am gonna clear with this for sure as there are many savvy people out here.

Anxiously waiting for the replies with plain simple approach and not using Jargon's.
 
Santosh Manikandan
Greenhorn
Posts: 9
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. A software service can be defined as a system meant to interoperate with other software systems (console,gui,server-based,middleware etc) probably written in some other language.
2. Servlets were never meant to provide "services". They are just Java classes which can participate in a request-response cycle under the HTTP protocol.
3. Servlets need a JavaEE compliant server to be hosted. Web services have no such requirements.
4. Servlets map a URI to a Java class which has a well-defined lifecycle (instantiation-init-service-do*-destroy). This gets further complicated with the addition of filters. Web services map a URI to a method/function which has a much simpler lifecycle.
5. Servlets can keep track of a web application's state and control its workflow. RESTful services are generally stateless and a simpler workflow.


Hope this helps
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at all the things JAX-RS does for you that you would need to reimplement if you were basing your solution purely on servlets, the question gets turned around to: why not use the available solutions instead of pure servlets?

You could also ask: Why use JSP, when I can emit HTML from a servlet? The answer is the same: because it's so much simpler to use what has already been implemented than implementing and debugging it yourself.
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Manikandan wrote:1. A software service can be defined as a system meant to interoperate with other software systems (console,gui,server-based,middleware etc) probably written in some other language.
2. Servlets were never meant to provide "services". They are just Java classes which can participate in a request-response cycle under the HTTP protocol.
3. Servlets need a JavaEE compliant server to be hosted. Web services have no such requirements.
4. Servlets map a URI to a Java class which has a well-defined lifecycle (instantiation-init-service-do*-destroy). This gets further complicated with the addition of filters. Web services map a URI to a method/function which has a much simpler lifecycle.
5. Servlets can keep track of a web application's state and control its workflow. RESTful services are generally stateless and a simpler workflow.


Hope this helps


Thanks for the insights !!!
 
Sangel Kapoor
Ranch Hand
Posts: 162
1
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:If you look at all the things JAX-RS does for you that you would need to reimplement if you were basing your solution purely on servlets, the question gets turned around to: why not use the available solutions instead of pure servlets?

You could also ask: Why use JSP, when I can emit HTML from a servlet? The answer is the same: because it's so much simpler to use what has already been implemented than implementing and debugging it yourself.


Alright, after reading your reply, i got one thing added to my awareness that JAX-RS internally solves the problem using the same basic Servlets technology.

But still, my orignal question remains unanswered......

Why we need another framework for Web Solutions like Struts 2 and Web services(REST) for Mobile kind of clients. For instance, in our project, we are using Struts 2 to cater web pages and RESTful web services via JAX-RS to
send data to Mobile (Android ) Clients. Can we just use 1 , either Struts2 or JAX-RS ? If we cannot then why ?

Looking Forward , hoping i am able to write my intentions for the question.....

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts and JAX-RS are used for quite different purposes (web GUIs vs. REST web services, respectively) - you can't substitute one for the other.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recall that REST is an architecture, not an API.

If you have been following the RESTful principles regarding the proper use of HTTP methods you have been doing REST for years.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!