0.3.0 ā€¢ Published 3 years ago

@kuasha420/oauth-fetch-json v0.3.0

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

Oauth Fetch JSON

Star IT Ltd

šŸ”„ An oauth client that fetches json. Works on node, react-native & browsers. šŸ”„

Installation & Usage

For node/react-native

Install with your favorite package manager.

Using Yarn:

yarn add @kuasha420/oauth-fetch-json

Using NPM:

npm i @kuasha420/oauth-fetch-json

Now import with ESM or CommonJS Syntax:

Using Named Exports

import { oauthFetchJson } from '@kuasha420/oauth-fetch-json';
const res = await oauthFetchJson(/*...*/);

Using Default Exports

import OFJson from '@kuasha420/oauth-fetch-json';
const res = await OFJson.oauthFetchJson(/*...*/);
// or, use alias fetch
const res = await OFJson.fetch(/*...*/);

For Browser

Add a script tag with the umd bundle from unpkg or release page.

<script src="https://unpkg.com/@kuasha420/oauth-fetch-json"></script>

Now you will have OFJson global in the window object.

Example

import { oauthFetchJson } from '@kuasha420/oauth-fetch-json';

const main = async () => {
  try {
    const res = await oauthFetchJson({
      url: 'https://www.exampla.org/api/v3',
      method: 'GET',
      consumer_key: '756uyh56uh5ru5yutr765uyhjgh67uryh675uhgr657uyr',
      consumer_secret: '657uyhgfh567hg765uhg75uyh567uhfgh756uhrytfu',
    });
    console.log(res);
  } catch (error) {
    console.error(error);
  }
};

main();

API

const oauthFetchJson: <Output = any>(
  request: Request,
  options?: Partial<Options>,
  extraHeaders?: Record<string, string>
) => Promise<Output>;

interface Request {
  url: string;
  method: string;
  body?: object;
  consumer_key: string;
  consumer_secret: string;
  access_token?: string;
  token_secret?: string;
}
export interface Options {
  cors: boolean;
  followRedirect: boolean;
}

License

This package is licensed under the MIT License.

Contribution

Any kind of contribution is welcome. Thanks!

Disclaimer

All APIS OF THIS PACKAGE ARE CONSIDERED UNSTABLE ACROSS VERSION UNTILL 1.0.

0.3.0

3 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago