@storyous/fetch
v1.1.0
Published
## Usage of fetch
Downloads
81
Keywords
Readme
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 });