Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keqingrong/http-client
A JavaScript HTTP client based on axios and fetch-jsonp
https://github.com/keqingrong/http-client
ajax axios fetch http-client jsonp request
Last synced: about 5 hours ago
JSON representation
A JavaScript HTTP client based on axios and fetch-jsonp
- Host: GitHub
- URL: https://github.com/keqingrong/http-client
- Owner: keqingrong
- License: mit
- Created: 2021-02-06T09:38:26.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-02-06T14:43:09.000Z (almost 4 years ago)
- Last Synced: 2024-10-29T06:57:36.636Z (19 days ago)
- Topics: ajax, axios, fetch, http-client, jsonp, request
- Language: TypeScript
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @keqingrong/http-client
[![npm version](https://img.shields.io/npm/v/@keqingrong/http-client.svg)](https://www.npmjs.com/package/@keqingrong/http-client)
A JavaScript HTTP client based on axios and fetch-jsonp
## Installation
```bash
# npm
npm install @keqingrong/http-client# yarn
yarn add @keqingrong/http-client
```## Usage
```ts
import { http, HttpClient } from '@keqingrong/http-client';interface ResponseData { }
(async () => {
try {
const response = await http.get(url);
// ...
} catch(err) {
// ...
}
})();
```## API
```js
// 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