0.7.4 • Published 5 years ago
oc-got v0.7.4
oc-got
Convenience wrapper for
got
to interact with Oracle Cloud application APIs. Inspired bygh-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:
headers.authorization
token
auth