UNPKG

@benshi.ai/js-sdk

Version:

Benshi SDK

42 lines (30 loc) 959 B
import axios from 'axios' import { NetworkProxy } from './typings' export default class BsNetwork implements NetworkProxy{ private config constructor(key: string) { this.config = { headers: { 'Authorization': `Bearer ${key}` } } } public async get(url:string):Promise<Object> { try { const fetchedData = (await axios.get(`${url}`, this.config)).data return fetchedData } catch (e) { console.error('Error retrieving data: ', e) throw new Error('error-fetching-data') } } public async send(url:string, payload: any):Promise<Object> { try { const postData = (await axios.post(url, payload, this.config)).data return postData } catch(e) { console.error('Error sending data: ', e) throw new Error('error-sending-data') } } }