Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebastiansulinski/js-caller
Lightweight axios wrapper.
https://github.com/sebastiansulinski/js-caller
ajax ajax-call ajax-request axios
Last synced: 22 days ago
JSON representation
Lightweight axios wrapper.
- Host: GitHub
- URL: https://github.com/sebastiansulinski/js-caller
- Owner: sebastiansulinski
- License: mit
- Created: 2020-05-22T12:18:05.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-09T08:40:06.000Z (about 4 years ago)
- Last Synced: 2024-12-09T20:58:16.600Z (about 1 month ago)
- Topics: ajax, ajax-call, ajax-request, axios
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# JS Caller
Lightweight [axios](https://github.com/axios/axios) wrapper pre-configured with the following headers:
```javascript
'X-Requested-With': 'XMLHttpRequest'
Accept: 'application/json'
'Content-Type': 'application/json'
```### Installation
```bash
npm i @ssdcode/js-caller
```### Usage
```bash
import Caller from '@ssdcode/js-caller';Caller.request(
'/end-point',
'post',
{ id: 1 },
{
timeout: 1000,
headers: { 'X-Custom-Header': 'foobar' },
}
);
````Caller.request` method takes 4 arguments:
```bash
- endpoint: request destination
- request method: get (default), post, put, patch, delete
- payload: data you wish to send with the request. If request method is in ['post', 'put', 'patch'] - payload will automaticaly be associated with 'data' index - otherwise 'params' will be used
- config: axios specific configuration
```If you're using `csrf` token, make sure it is included as a meta tag and `js-caller` will fetch and attach it to the request automatically as a `X-CSRF-TOKEN` header.
```html
```