DevArt EichJS Communication Base
From DevArt Knowledgebase
Communication Base is a library allowing you to develop communication service classes using Vanilla JavaScript.
Info
- Developer: DevArt Software Co.
- Contributors: Pathum Bandara Premaratne
- Latest Version: v1.0 @2023-07-07
- URL: https://js.devartsoftware.com/devart/communication/v1.0/devart.communication.base.min.js
Dependencies
jQuery v3.6.0 - URL: https://js.devartsoftware.com/jquery/v3.6.0/jquery.min.js EichJS Extender Main v1.0 - URL: https://js.devartsoftware.com/devart/extender/main/v1.0/devart.extender.min.js EichJS HttpRequest v1.2 - URL: https://js.devartsoftware.com/devart/httprequest/v1.2/devart.httprequest.min.js (Use v1.3 for UCG v1.1 or v1.4+ for UCG v2.0)
Enum : Executions
Enum that contains the HTTP Methods which are allowed in communication base service.
* Executions.Get * Executions.Post * Executions.Put * Executions.Delete
BaseService
Base class that can be used to create child communication service classes. The service caller is pre-built into this class.
Constructor
@params
{String} URL Base URL of the web-based API.
{HttpHeader[]} Headers Array of headers that are required to communicate with the web service.
{function} FnGlobalFail Function to be executed when a global level error occurs.
{boolean} Silent Visual loader switch.
{function} FnShowLoader Function to be executed to show the loader.
{function} FnHideLoader Function to be executed to close the loader.
Methods
Check
Checks the connectivity between the client and the service.
Execute
Execute the operation requested by the client.
@params
{Executions} Mode Specifies which HTTP Method to be used.
{string} Function Function/Web Method/Controller name to be called.
{any} Payload Payload to be sent to the web service.
{function} FnSuccess Handler to the triggered on a successful service call.
{function} FnFail Handler to the triggered on a failed service call.
Demo
URL: https://ejs.api.demo.devart.asia
Sample Code
let _BaseURL = "https://ejs.api.demo.devart.asia"; let _Headers = new Array(); let FnGlobalFail = function (Response) { alert("Communication error." + JSON.stringify(Response)); }; var FnShowLoader = function () { }; var FnHideLoader = function () { }; //Proxy Class class Engineer { constructor(Id, Name) { this.Id = Id; this.Name = Name; } } //Service Class class EngineerService extends BaseService { constructor() { super(_BaseURL + "/engineer", Headers, FnGlobalFail, true, FnShowLoader, FnHideLoader); } GetAll(FnProcessor) { super.Execute(Executions.Get, String.Empty, undefined, FnProcessor); } Get(Id, FnProcessor) { super.Execute(Executions.Get, Id, undefined, FnProcessor); } Post(Employee, FnProcessor) { super.Execute(Executions.Post, undefined, Employee, FnProcessor); } Put(Id, Name, FnProcessor) { super.Execute(Executions.Put, Id, Name, FnProcessor); } Delete(Id, FnProcessor) { super.Execute(Executions.Delete, Id, undefined, FnProcessor); } }
