JavaScript Library
Without Finesse JavaScript library
In the absence of the Finesse JavaScript library, the following code would be needed to pull the User details after the login process is completed.
-
Make a GET call to the server to get the details of this agent.
Example—GET
-
Make a PUT call to the server to change the state of this agent.
Example—PUT
REST operations such as POST and DELETE can also be performed on the User API to get the desired result.
With Finesse JavaScript library
In the presence of the Finesse JavaScript library, the following code would be needed to pull the User details, where the User object is under the namespace finesse.restservices.User
.
-
Make a GET all on the User API. The GET call in the above example is made using the jQuery OpenAjax API, where the
onLoad
is equivalent to thesuccess
option of the jQuery OpenAjax call.Example—onLoad, onChange, and on Error
The
onChange
is equivalent to thesuccess
option in PUT jQuery OpenAjax call made to modify the state of the User in the second example. Similarly, there are other handlers such asonAdd
used for POST request andonDelete
used for DELETE requests which are supported by User object as well as other Finesse JavaScript objects. Update the state of the User using the
Example—Update State of a UsersetState()
provided by finesse.restservices.User.The above example triggers a state change for the User, which is equivalent to make a PUT request, which in turn triggers the
onChange
handler attached to the User object.All the handlers (GET, PUT, POST, DELETE, ERROR) can be attached to the object during initialization. Initialization of a JavaScript object triggers a GET request, the response of which is used to populate the JavaScript object. There are APIs available within the JavaScript object to create, update, and delete certain compositions (in the JavaScript object itself) that internally trigger PUT, POST, and DELETE REST API request respectively.
To put this into perspective, the Finesse JavaScript REST API objects try to encapsulate the low-level request or response handling at the client-side and provide with APIs which are easy to use, maintain and improve the readability of the code.