dthttp
v2.0.0-beta25
Published
Simple class-based HTTP client with Promises
Downloads
16
Maintainers
Readme
Simple class-based HTTP client with Promises
Start Working:
const API = new dtHttp('http://doge.in/wow/');
API.get('lol').then(function (response) {
console.log(response);
});
Defining custom promise prototype;
const API = new dtHttp('http://doge.in/wow/', myPromisePrototype)
Working with AngularJS
angular.module('myApp').factory('$API', function ($q) {
return new dtHttp('http://doge.in/wow/', $q);
})
Request Middleware
const myMiddleWare = function (response, resolve, reject) {
if (response.status === 401) {
window.location.path = '/login';
reject(response);
} else {
resolve(response);
}
};
API.applyMiddleware(myMiddleWare)
Method Support
Supports
- GET
.get(ResourcePath, GET-params)
- POST
.post(ResourcePath, body)
- PUT
.put(ResourcePath, body)
- PATCH
.patch(ResourcePath, body)
- DELETE
.del(ResourcePath)