Getting Started
import createApi from '@exodus/asset-json-rpc'
const api = createApi(url)
const api = createApi(url, { headers: { FOO: 'BAR' } })
const result = await api.post({ method: 'hello' })
api.post({ method: 'hello', params: [1] })
api.post({ method: 'hello', params: [1], id: 2, jsonrpc: '2.0' })
Handle Errors
const api = createApi(url)
.middlewares([
(next) => async (url, options) => {
const res = await next(url, options)
let retry, message
if ([500].includes(res.status)) {
message = `${res.status} ${res.statusText}`
retry = true
} else {
return res
}
throw new ApiError(message, { retry })
}
])