ExoVision
Call remote HTTP RESTful services in easy way, both in browser and Node.js.
import exovision from 'exovision'
const myRemoteService = exovision('MY_REMOTE_SERVICE')
const myRemoteService2 = exovision('https://myremoteservice.com')
myRemoteService.get()
myRemoteService.post()
myRemoteService.put()
myRemoteService.del()
All methods have same signature:
type ExovisionBoundTransmit = (
path: string,
data?: any,
options?: ITransmissionOptions,
) => Promise<any>
This is ITransmissionOptions interface:
interface ITransmissionOptions {
contentType?: string
responseType?: string
transcodeResponse?<O, T>(data: O): T | Promise<T>
echoCall?: boolean
token?: string
}
transcodeResponse: custom transformation function. For example, if you need to convert xml to json you can pass a transform function that will be invoked after the remote call is done:
import { parse } from 'fast-xml-parser'
const trasformXmlToJson = (data: any) =>
parse(data, { ignoreAttributes: false, attributeNamePrefix: '' })
myRemoteService.get('/rabbids', {}, {
contentType: 'text/xml',
responseType: 'text',
transcodeResponse: trasformXmlToJson
})
All methods return a promise with parsed content (content type is JSON) or whatever transcodeResponse custom function returns.
In case of error during remote call it will be rertuned a rejected promise with
interference instance