1.0.6 • Published 2 years ago

@hatsa/fetch v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@hatsa/fetch

A simple axios wrapper that has google cloud related features inside. For example, request authorization for IAP-protected endpoints.

Usage

Basic request

import { fetch } from '@hatsa/fetch';

const response = await fetch(`https://${domain}`);

Google Cloud Api

Endpoints protected by Identity-Aware Proxy

import { createApiInstance } from '@hatsa/fetch';

const api = createApiInstance({
  name: 'affiliates',
  config,
  iapClientId: 'TODO-PUT_IAP_CLIENT_ID-HERE',
});

type Product = {
  id: string;
  title: string;
};

const { data: products } = await api.get<Product[]>(`/${affiliate}/${programId}/${feedId}/${output}`, {
  params: { limit },
});

Stream

const { stream } = require('@hatsa/fetch');
const { pipeline } = require('stream');
const util = require('util');
const fs = require('fs');

(async () => {
  const url = 'https://picsum.photos/200/300.jpg';
  const { status, data: apiStream } = await stream(url);
  const runPipeline = util.promisify(pipeline);

  await runPipeline([apiStream, fs.createWriteStream('photo.jpg')]);
})();
1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago