Socket
Book a DemoInstallSign in
Socket

@exodus/asset-json-rpc

Package Overview
Dependencies
Maintainers
104
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@exodus/asset-json-rpc

For all assets

2.0.2
latest
Source
npmnpm
Version published
Maintainers
104
Created
Source

Getting Started

import createApi from '@exodus/asset-json-rpc'

const api = createApi(url)
const api = createApi(url, { headers: { FOO: 'BAR' } }) // custom headers

// JSON-RPC
// request: { method: 'hello', params: [], id: 1, jsonrpc: '2.0' }
// response: { result: 'world', id: 1, jsonrpc: '2.0' }
// response with error: { error: { code: 100, message: 'danger', data: {a : 1} }, id: 1, jsonrpc: '2.0' }

const result = await api.post({ method: 'hello' }) // params can be omited
// result -> 'world'
// error -> throw new Error('danger') with properties { code: 100, data: { a: 1 } }

api.post({ method: 'hello', params: [1] }) // pass params
api.post({ method: 'hello', params: [1], id: 2, jsonrpc: '2.0' }) // can override id etc

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 })
    }
  ])

FAQs

Package last updated on 03 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.