chickendinosaur-http
Version:
Front-end, super slim, ajax, xhr, http library with promises.
2 lines • 1.17 kB
JavaScript
!function(t,e){"function"==typeof define&&define.amd?define(["./../../es6-promise/promise.min.js"],e):"object"==typeof exports?module.exports=e(require("es6-promise")):(t.ChickenDinosaur=t.ChickenDinosaur||{},t.ChickenDinosaur.Http=e(t.ES6Promise))}(this,function(t){"use strict";function e(){this.get=function(t,e){return r("GET",void 0===e?t:o(t,e))},this.post=function(t,e,n){return r("POST",void 0===n?t:o(t,n),e)},this.put=function(t,e,n){return r("PUT",void 0===n?t:o(t,n),e)},this.delete=function(t,e){return r("DELETE",void 0===e?t:o(t,e))}}var n=t.Promise,i=function(t){var e;try{e=JSON.parse(t)}catch(n){e=t}return e},r=function(t,e,r){var o=new n(function(n,o){var s="undefined"!==XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");s.open(t,e,!0),s.setRequestHeader("Content-type","application/json"),s.onreadystatechange=function(){this.readyState===this.DONE&&(200===this.status?n(i(this.responseText)):o(this))},"POST"===t||"PUT"===t?s.send(JSON.stringify(r)):s.send()});return o},o=function(t,e){var n=t.toString();for(var i in e)n+=-1!==t.indexOf("?")?"&":"?"+i+"="+e[i];return n};return new e});
//# sourceMappingURL=Http.min.map