1

I have repeatedly searched for, and come across questions and answers on the possibilities of accessing session-, and requestscoped data with client side javascript or similar. The answer seems to be a consistent "no you can't do that". But the Front Controller pattern, as described here, forwards the java objects for request and response, and exposes them for retrieval in the browser, through Expression Language.

To me this seems like a great approach, as it passes along data at the same time as the redirect. In other words, if the web page has a table that should be populated with default, but currently updated data (say weather report for next week). All other approaches seems to include loading the website first, and then loading data to populate, through ajax or similar.

I've been starting to look at angular, and RESTful api's, and I am having a hard time grasping even the basics. One of the upsides of angular, should be it's ability to divide front side code into modules, and include template html's, without loading them seperately. But it seems like in a RESTful api, I can't pass along dynamic initial values to be displayed on a page.

So with a RESTful api structure, am I right to assume that I need to load the page first, and then retrieve the data through the $http-service? And if so, why is it designed, so that I need to make a double (or multiple) request to the server? If not, how can I pass data to the page, as the server redirects to it? Am I wrong to use redirects in the first place?

Community
  • 1
  • 1
jumps4fun
  • 3,994
  • 10
  • 50
  • 96

1 Answers1

0

Know this is an old question, and not certain I am the best man to answer this question, but as I am struggling a little bit with this (or a similar question).

Answer to your first question is probably more to do with rendering and how web browsers do things. (I may be wrong, so feel free to tell me off).

When the server receives a http request (i.e. visitor opening www.yourpage.com) it will start sending data streams. Depending on how your webpage, something along the lines of index.html to start with, in index.html you will have a number of hooks such as maybe a section.html, css files, pictures and javascript files.

Once the javascript files start arriving the javascript engine starts processing the code (well, the web browser starts sending the data from to the assigned program or compiler). Once that starts up, it kind of runs as a separate program, which have some hooks into the web browser. And while that is still booting up, the browsers rendering engine will be processing the html code, create DOM objects and all other bits it needs.

As for the server, in almost all cases, the data needs to be sent from the server side to the browser as a text string, the browser then forwards it to the program running in the compiler or interpreter. If you trace or snoop network traffic you will se the JSON strings go past.

You will also have to wait until your program or code is running before you send the JSON, as to the web browser, it is just a text string, test it by making one of the api calls in the browser directly.

This is why you will need to let the java code start first, then make a api call to the server, then read the returning string into some kind of structure.

Hope this helps

vrghost
  • 1,084
  • 2
  • 19
  • 42