From bcfaf5175f68df4688901be155b93ee36e4d8408 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Mon, 26 Dec 2016 14:13:49 +0700 Subject: [PATCH] Add API section to readme --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index 862be8a..9fce7d1 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,51 @@ const onionoo = new Onionoo({ }); ``` +## 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`, `boolean`
+Default: `{ store: 'memory', max: 500 }` + +Options object to be merged with default options and passed to [`node-cache-manager`](https://github.com/BryanDonovan/node-cache-manager). Alternatively, if set to false, caching will be disabled. + +### 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](https://onionoo.torproject.org/protocol.html#methods). + +> Note: Semicolons are not url encoded to allow for Onionoo's `key:value` search filters. + ## License MIT © Luke Childs