Skip to content

keqingrong/http-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@keqingrong/http-client

npm version

A JavaScript HTTP client based on axios and fetch-jsonp

Installation

# npm
npm install @keqingrong/http-client

# yarn
yarn add @keqingrong/http-client

Usage

import { http, HttpClient } from '@keqingrong/http-client';

interface ResponseData { }

(async () => {
  try {
    const response = await http.get<ResponseData>(url);
    // ...
  } catch(err) {
    // ...
  }
})();

API

// GET method
http.get(url);
http.get(url, { foo: 'bar' });
http.get(url, new URLSearchParams());

// POST method
http.post(url, { foo: 'bar' });

// Shortcuts POST method
http.postFormUrlencoded(url, { foo: 'bar' });
http.postFormUrlencoded(url, new URLSearchParams());
http.postFormData(url, new FormData());
http.postJSON(url, { foo: 'bar' });

// JSONP
http.jsonp(url);
http.jsonp(url, { foo: 'bar' });
http.jsonp(url, new URLSearchParams());

// Custom
http.request({
  url,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  }
  data: { foo: 'bar' }
});

License

MIT © Qingrong Ke

About

A JavaScript HTTP client based on axios and fetch-jsonp

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published