rstarter-supporthq
Version:
53 lines (51 loc) • 1.84 kB
JavaScript
export default class ApiHandaler {
constructor(url,AppKey,Key){
this.url=url;
this.AppKey=AppKey;
this.Key=Key;
this.getData = this.getData.bind(this);
this.postData = this.postData.bind(this);
this.postFormData = this.postFormData.bind(this);
this.getAll = this.getAll.bind(this);
}
getData(url,data,callback){
fetch(url,{
method:"GET",
body:JSON.stringify(data)
}).then(res=>res.json()).then(function (res) {
callback(res);
});
}
postData(url,data,callback){
fetch(url,{
method:"POST",
body:data
}).then(res=>res.json()).then(function (res) {
callback(res);
});
}
postFormData(url,formData,callback){
fetch(url,{
method:"POST",
body:formData
}).then(res=>res.json()).then(function (res) {
callback(res);
});
}
getAll(moduleName,callback){
const url=this.url+"/api/AppKey/"+this.AppKey+"/Module/"+moduleName+"?key="+this.Key;
this.getData(url,{},callback);
}
getWithPerpage(moduleName,page,perPage,callback){
const url=this.url+"/api/AppKey/"+this.AppKey+"/Module/"+moduleName+"?key="+this.Key+"&page="+page+"&perpage="+perPage;
this.getData(url,{},callback);
}
insertItem(moduleName,data,callback){
const url=this.url+"/api/AppKey/"+this.AppKey+"/Module/"+moduleName+"/store?key="+this.Key;
this.postData(url,data,callback);
}
getDataWithID(moduleName,id,callback){
const url=this.url+"/api/AppKey/"+this.AppKey+"/Module/"+moduleName+"/get/"+id+"?key="+this.Key;
this.getData(url,{},callback);
}
}