1.0.5 • Published 3 years ago

@ssdcode/js-caller v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

JS Caller

Lightweight axios wrapper pre-configured with the following headers:

'X-Requested-With': 'XMLHttpRequest'
Accept: 'application/json'
'Content-Type': 'application/json'

Installation

npm i @ssdcode/js-caller

Usage

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:

- 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.

<meta name="csrf-token" content="{{ csrf_token() }}">
1.0.5

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago