Skip to content

Latest commit

 

History

History

api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@blocker/steem-api

Modern and lightweight JavaScript library to consume the Steem API.

npm version Known Vulnerabilities Maintainability

Modern and lightweight JavaScript library to consume the Steem API.

Get started

Install

yarn add @blocker/steem-api node-fetch
# or
npm install @blocker/steem-api node-fetch

You can use any library that supports the WHATWG fetch specification.

Usage

import fetch from 'node-fetch'
import { HttpAdapter, ApiClient } from '@blocker/steem-api'

const adapter = new HttpAdapter({ fetch })
const client = new ApiClient({ adapter })

client.tags.getTrendingTags({ limit: 2 })
  .then(data => {

  })

demo RunKit

ApiClient

ApiClient uses Proxy and Reflect to simplify its use.

Send requests with Proxy feature

Syntax: client[api_name][method_name](params)

client.database_api.list_savings_withdrawals({ start: 10, limit: 55 })
  .then(result => {  })

You can omit the _api suffix in api_name and use camelCase in api_name and method_name.

client.database.listOwnerHistories({ start: 10, limit: 55 })
  .then(result => {  })

Send requests without Proxy feature

However it is possible to send requests without using this feature.

There are 3 ways to use the send method.

client.send(api_name, method_name, params)
client.send(full_method_name, params)
client.send(full_payload)

Exemples

client.send('database_api', 'list_savings_withdrawals', { start: 10, limit: 55 })
client.send('database_api.list_savings_withdrawals', { start: 10, limit: 55 })
client.send({
  method: 'database_api.list_savings_withdrawals',
  params: { start: 10, limit: 55 }
})

Adapters

ApiClient uses adapters to send requests. Currently the only available adapter is the HttpAdapter.

HttpAdapter

The HttpAdapter constructor receives the function an object as an argument, within that object the fetch instance must be passed as argument.

import fetch from 'node-fetch'
import { HttpAdapter } from '@blocker/steem-api'

const adapter = new HttpAdapter({ fetch })