function HttpService(){} HttpService.prototype = { _send : function(cfg){ return new Promise(function(resolve,reject){ cfg["headers"] = { 'Authorization': 'QEusiOidV6pScOHsfaOMZHr0Kv5cFUXKS1IYGmwQw03Rv8u4OcC0vw4xOSv8oZXj' } $.ajax(cfg) .always(function(data, textStatus, jqXHR){ if (jqXHR['status'] == 200 && jqXHR['readyState'] == 4) { resolve(data); } else { reject(textStatus); } }); }) }, get : function(url,dataType){ return this._send({ dataType: dataType || 'json', url: url, type: 'GET', }); }, delete : function(url){ return this._send({ dataType: 'json', url: url, type: 'DELETE', }); }, post : function(url,dados){ return this._send({ dataType: 'json', contentType: 'application/json', url: url, type: 'POST', data:JSON.stringify(dados), }); }, put : function(url,dados){ return this._send({ dataType: 'json', url: url, type: 'PUT', data:JSON.stringify(dados), }); }, custom : function(params){ return this._send(params); } }