@haensl/google-cloud
Version:
Useful things around Google Cloud
61 lines (38 loc) • 1.45 kB
Markdown
Useful utitlities for working in Google Cloud.
[](https://nodei.co/npm/@haensl%2Fgoogle-cloud/)
[](http://badge.fury.io/js/@haensl%2Fgoogle-cloud)
[](https://circleci.com/gh/haensl/google-cloud)
```bash
npm i --save @haensl/google-cloud
```
Get authorization to call a URL. This is useful to authorize requests between services within Google Cloud.
`url`: `string|URL`
The URL you want to call.
The Authorization header for the request to the given URL.
```javascript
const { getAuthorization } = require('@haensl/google-cloud');
const fetch = require('node-fetch');
const callOtherService = async () => {
// ...
const otherService = new URL('https://myservice-1234567890.region.run.app');
const authorization = await getAuthorization(otherService);
const requestOptions = {
method: 'GET',
headers: {
'Authorization': authorization
}
};
const response = await fetch(otherService, requestOptions);
// ...
};
```