Routing on the client side

Figure 5.2 depicts routing from the perspective of the client side in an Isomorphic Go application, implementing the single page application architecture.

In Figure 5.1, the client side played a trivial role in simply rendering the web page server response. Now, in addition to displaying the rendered web page, the client contains a request router, route handlers, and the application business logic inside of it.

We will use the isokit router from the isokit package to perform client-side routing. The client-side router works much in the same manner as the server-side router, except instead of evaluating an HTTP request, the router intercepts the click of a hyperlink defined on the web page and routes it to a particular route handler defined on the client side itself. The client-side route handler that services a particular route, interacts with the server through a Rest API endpoint that is accessed by making XHR requests. The response from the web server is data that can take on a variety of formats, such as JSON, XML, Plain Text, and HTML Fragment, or even Gob-encoded data. We will use JSON as our means of data exchange in this chapter. The business logic of the application will determine how the data is handled, and it may be displayed to the user in the user interface. At this point, all rendering operations can take place on the client side, allowing us to prevent a full page reload:

Figure 5.2: End to End Routing consists of a router on both ends
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.199.181