Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why are there two types of methods for a particular operations in a project?  RSS feed

 
Ranch Hand
Posts: 113
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a confusion regarding "Web Services",
Assume there is an 'Employee Management Web application'.
You have to perform a task that is to display all the records of employees from 'Employee' table.
you have written an 'EmployeeController' class where you are returning the "List" of employee objects to the browser through ModelAndView object, you even mentioned the "view" page name as well:



Now here it leaves me confused....the below written RESTful WS method performs the same task what the above method does but it sends the Employees objects in JSON format.
I want to know when does the above method has to execute and when this below one?
How relevant are both to each other?
Does every java based web project contains both types of methods for a particular operations?

I hope you have understood what i want to ask. Your help will be much appreciated. Thanks!
 
Saloon Keeper
Posts: 1596
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that this codereturns object list named "employees" for the view named "page".
This view would most likely generate some document (often HTML or PDF) and a listing of objects as created by the view and template engine.

"/show/allEmployees" is the data rendered and ready for immediate presentation (usually via web browser) thanks to the logic provided by the view.

However this code:only returns the data without any extra markup. This data is most likely returned at a listing of JSON or XML objects.

The "allEmployees" call is a REST call which would be consumed by another program, maybe IOS, Android etc. This is only the data and nothing but the data.
Usually the consuming program has to add some extra display elements/design to the data before being displayed.

They are related in that they provide the same information, but in different ways for the consuming client.

Arun Singh Raaj wrote:Does every java based web project contains both types of methods for a particular operations?


No, as there is not always a reason do. Some data should not be consumed via REST for business reasons or other reasons.
Often most only program what they have to and nothing else. So you may see REST data or you may just regular data or you may see both.
Depends on what the project needs to provide to the end users/consumers.
 
Saloon Keeper
Posts: 8889
166
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends heavily on whether your application's presentation layer is mostly in the client or in the server.

For instance, it's possible to have an application that consists of a lot of static HTML pages, and every time you make a request the server builds a new web page. In this case, your server will mostly have methods of the first kind, that return a ModelAndView.

The other extreme is an application that consists of a single dynamic web page. In this case, the server has one method that returns a ModelAndView containing the entire client-side application, and all interaction with the server is done through AJAX requests that get handled by methods of the second kind, that return a JSON response body.

Most web applications are somewhere in the middle. They host a couple of different HTML pages, which to a varying degree communicate with the server with AJAX request.
 
Arun Singh Raaj
Ranch Hand
Posts: 113
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for clearing that up... Stephan van Hulst, Pete Letkeman.
 
Trust God, but always tether your camel... to this tiny ad.
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!