Modern and lightweight JavaScript library to consume the Steem API.
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.
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 => {
})
ApiClient uses Proxy and Reflect to simplify its use.
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 => { })
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 }
})
ApiClient uses adapters to send requests. Currently the only available adapter is the 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 })