RestBase Common Parameters
All the JavaScript objects extend from the RestBase class. There is some common configuration that can be passed into each of these objects during initialization.
Example—Common Configurations
Example—Options
Parameter | Description |
Example |
---|---|---|
id |
An ID that uniquely identifies the JavaScript object. |
For a User API, this is the id or username which uniquely identifies that User. Every REST API object has a unique identifier. You cannot generate this on the client-side. Each JavaScript object is a representation of an already existing REST API object on the system. A user with that id is already present in the upstream system, and you are instantiating a JavaScript version of it on the client-side. |
onLoad |
A callback that is invoked one time in the life of the object, which is when the initialization is successful and the data is loaded into the JavaScript object successfully. This JavaScript object is then passed to the handler as a parameter. This is equivalent to the success handler of a GET REST API request. |
An example of a User JavaScript object loading: |
onChange |
A callback that is invoked upon the successful update of the object. The updated object is then passed to the handler as a parameter. This is equivalent to the success handler of a PUT REST API request. |
An example where the User's state changes and shows an alert to the user: In the above example, the Agent is alerted when the state changes to NOT_READY. |
onAdd |
A callback that is invoked when an object is created in the upstream system by doing a POST request from the client. The client receives a success response for the creation. The newly created object is passed to the handler as a parameter. This is unlike the other scenarios where the JavaScript object is pre-existing in the system and you are creating a JavaScript version that creates a new object in the system. |
Currently, there are no such instances where you are using the JavaScript object to create an object that is not present in the upstream system. |
onDelete |
A callback that is invoked when an object is deleted in the upstream system by doing a DELETE request from the client. The client receives a success response for the deletion. |
Currently, there are no such instances where you are using the JavaScript object to delete an object that is there already in the upstream system. |
onError |
A callback that is invoked with the response object as the parameter when any of the operations such as, GET, PUT, POST and DELETE fails. The following are the parameters:
|
An example when the operations fail: |