0.7.4 • Published 5 years ago

oc-got v0.7.4

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

oc-got npm

Convenience wrapper for got to interact with Oracle Cloud application APIs. Inspired by gh-got.

Install

npm install oc-got

Usage

Instead of:

const got = require('got');
const token = 'qux';

(async () => {
  const { body } = await got('https://foo.bar.oraclecloud.com/baz', {
    json: true,
    headers: {
      'authorization': `Bearer ${token}`,
      'REST-Framework-Version': '3'
    }
  });

  console.log(body);
})();

You can do:

const ocGot = require('oc-got');

(async () => {
  const { body } = await ocGot('https://foo.bar.oraclecloud.com/baz', {
    token: 'qux',
    version: 3
  });

  console.log(body);
})();

And instead of:

const got = require('got');

(async () => {
  const { body } = await got('https://foo.bar.oraclecloud.com/baz', {
    headers: {
      'Accept': 'text/xml',
      'Content-Type': 'text/xml',
    }
  });

  console.log(body);
})();

You can do:

const got = require('got');

(async () => {
  const { body } = await got('https://foo.bar.oraclecloud.com/baz', {
    xml: true
  });

  console.log(body);
})();

API

Same as got, but with some additional options below.

oc-got specific options

token

Type: string

If provided without an authorization header, it will be set to Bearer ${token}.

version

The version of the REST Framework to use.

xml

Type: boolean Default: false

Note: If true, json will be set to false.

If true, then the Accept and Content-Type headers will be set to text/xml if not provided.

Authorization

Precedence is given to options in the following order to determine how the authorization header is set:

  1. headers.authorization
  2. token
  3. auth

License

MIT

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago