HomeClarion Live! UniversityJSON and "consuming services"
  • PDF

JSON and "consuming services"

James Fortune ASKED: 


The only part of that I'm still having trouble with is ... JSON. What are "services"? What does "the the services are consumed using screen-only code, no code behind" mean? What is the concept of "consuming" a service?


James Cooke REPLIED:


• James, on JSON: You have a Web page with a button called "Get Customers".

Usually when the button is clicked, the page is submitted back to the server with the event instruction "Get Customers was clicked". The GetCustomers() method is invoked, the database is read and the web page is rewritten internally with all the customers on it, then sent back to the browser. That sounds expensive. It is.

JSON provides the ability for the web page to stay, in its current form, on the users web browser, but a Javascript (JSON) module, which executes on the web browser only, issues the instruction for the server to send only the data, then the JSON code on the browser would display it in the Grid on the web browser. The page wasnt re-written by the server, only modified by the JSON code on the browser. The server didnt have to do anything but send the raw data back to the browser. Very inexpensive.

So the question remains, how does the JSON code talk to the database? Thats where a service comes in. The service could very loosely be referred to as a web page - it is treated that way and even has a URL that looks something like this:


Instead of an expensively formatted page coming back, a simple chunk of XML comes back containing a list of customers. The JSON code knows how to read this and takes it and turns it into a list of customers, and it then dumps it in the grid.

So you "consumed the service" by running the URL in the browser, waiting for a response, then eating the results that came back. A Clarion app consumes the service of a TPS driver. We issue a Get(Customer) statement, (or invoked the TPS Driver service) and Consumed the results of the GET() by saying ?Label1{prop:text}=Cus:Name. Its all the same thing really, just named differently to show a clear differentiation of the different pieces - "separation of concerns". The data service does its thing, the client doesn't care about how it did it, just expects the results.

Joomla Templates: by JoomlaShack