dthttp

Simple class-based HTTP client with Promises

Usage no npm install needed!

<script type="module">
  import dthttp from 'https://cdn.skypack.dev/dthttp';
</script>

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)