@keqingrong/http-client
v0.1.0
Published
A JavaScript HTTP client based on axios and fetch-jsonp
Downloads
3
Maintainers
Readme
@keqingrong/http-client
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