http library typeScript / es6
live exapmle (https://openup.github.io/httpClient/)
GET
http.get(url, headers : {}); // headers are Additional (Option)
POST
http.post(url, params : {}, headers : {}); // params & headers are Additional (Option)
Abort
http.abort(); // no args needed; cancel current request
you need to compile to JS or integrate the js file
don't forget to integrate the class file in your html 🀄 <script src="httpClient.min.js"></script>
const http = new Http(); // by default return JSON , if want text declare new Http('text');
let post_url = "http://httpbin.org/post";
let get_url = "http://httpbin.org/headers";
// for GET request
http.get(get_url).then((res) => {
console.log('Success : ', res);
}).catch((err) => {
console.log('Error : ', err);
});
// for POST request **(add json as data params)**
http.post(post_url, {key : value}).then((res) => {
console.log('Success : ', res);
}).catch((err) => {
console.log('Error : ', err);
});
// to cancel a current request
http.abort();