1.0.6 • Published 1 year ago

@storyous/fetch v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

fetch

Usage of fetch

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

const url = 'https://example.com';

// basic fetch
const resp = await fetch(url, { timeout: 50 };

// returns automaticly parsed JSON response into object
const json = await fetch.json(url);

// returns plaintext from response payload
const text = await fetch.text(url);

Usage of MongoCachedJsonFetcher

import { Collection } from 'mongodb';
import { getMongoCachedJSONFetcher } from '@storyous/fetch';

const url = 'https://example.com/file.json';

const collection: Collection = mongoClient.collection('cachedFiles');
const fetchTheJson = await getMongoCachedJSONFetcher(collection, { url });

Usage of storyousAuthorizedFetch

import { storyousAuthorizedFetch } from '@storyous/fetch';

const serviceUrl = 'https://secured.example.cz/endpoint';
const loginUrl = 'https://authorize.something.com/login';
const clientId = 'someClientId';
const clientSecret = 'someClientSecret';

const resp = await storyousAuthorizedFetch(serviceUrl, { loginUrl, clientId, clientSecret });