1.1.7 • Published 5 months ago

lesca-fetcher v1.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

NPM React React React React React NPM

Integrate fetch for easier use.

Installation

npm install lesca-fetcher --save

Usage

import Fetcher, { contentType, formatType } from 'lesca-fetcher';

Fetcher.install({
  hostUrl: 'https://yourhost.com/api/',
  contentType: contentType.JSON,
  formatType: formatType.JSON,
});

Fetch.setJWT('Fsr.956b6.67ktJGr'); // if necessary


<button
  onClick={() => {
    const path = '/save';
    const data = { name: 'myName', age: '18' };
    Fetcher.post(path, data).then((respond) => {
      console.log(respond);
    });
  }}
>post</div>;

<button
  onClick={() => {
    const path = '/get';
    Fetcher.get(path).then((respond) => {
      console.log(respond);
    });
  }}
>get</div>;

Development

Methods

methoddescriptiondefault
.install(config:object)install first
.post(api:string, data:object)POST
.get(api:string)GET
.setJWT(token):stringset JWT Token
.postStringify(api:string, data:object):stringpost and stringify
.mergePath(api:string):stringget full path

config

const config = {
  hostUrl: 'https://www.yourHost.com/api/', // string
  contentType: contentType.JSON, // enum contentType.JSON || contentType.URL_ENCODED
  formatType: formatType.JSON, // enum formatType.JSON || formatType.string
};

Features

  • maintain if necessary
1.1.7

5 months ago

1.1.1

7 months ago

1.1.0

8 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago