onionoo-node-client
Node.js client library for the Tor Onionoo API
Promise based client library for the Tor Onionoo API. Includes DB agnostic caching.
Install
npm install --save onionoo
Usage
const Onionoo = ;const onionoo = ; // Get top 10 relaysconst query = limit: 10 running: true order: '-consensus_weight'; onionoosummaryquery;
You can override the default options when instantiating a new Onionoo
instance:
const Onionoo = ;const onionoo = baseUrl: 'https://onionoo.torproject.org' endpoints: 'summary' 'details' 'bandwidth' 'weights' 'clients' 'uptime' cache: false;
Cache
By default no cache is used. You can easily cache in memory or to a more scalable store like Redis using Keyv storage adapters.
Cache in memory:
const Onionoo = ; const memory = ;const onionoo = cache: memory ;
Use persistent Redis cache:
const Onionoo = ;const KeyvRedis = ; const redis = 'redis://user:pass@localhost:6379';const onionoo = cache: redis ;
API
new Onionoo([options])
Returns a new Onionoo
instance
options
Type: object
options.baseUrl
Type: string
Default: 'https://onionoo.torproject.org'
String to use as the base url for all API requests.
options.endpoints
Type: array
Default: ['summary', 'details', 'bandwidth', 'weights', 'clients', 'uptime']
Array of endpoints to be returned as methods on the Onionoo
instance.
options.cache
Type: object
Default: false
Keyv storage adapter instance for storing cached data.
onionoo.endpoint([query])
Where endpoint is an item from the endpoints array
Returns a Promise that will resolve once the Onionoo API has responded. The response object contains statusCode
, statusMessage
, headers
and body
properties.
query
Type: object
Query object to be url encoded and appended to the baseUrl
. You can read up on the vast amount of accepted parameters in the Onionoo API docs.
Note: Colons are not url encoded to allow for Onionoo's
key:value
search filters.
Related
Onionite
- Explore the Tor network
License
MIT © Luke Childs