dthttp

2.0.0-beta25 • Public • Published

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)

Package Sidebar

Install

npm i dthttp

Weekly Downloads

4

Version

2.0.0-beta25

License

MIT

Last publish

Collaborators

  • evgenyrodionov