From 1e94db5b9e647c8677d759b1688840696813c9ae Mon Sep 17 00:00:00 2001 From: Mirellys Arteta Davila Date: Tue, 6 Feb 2018 17:02:29 +0100 Subject: [PATCH] docs: add documentation for trembita usage on plugins. --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index fbd174a..946f537 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,45 @@ yarn add trembita ## Usage Trembita is not supposed to be used directly, rather than to develop plugins. +In order you can use a third party service by implementing your plugin, make sure you fill the next requeriments: + +- Extend Trembita module. +- Construct the plugin by implementing the properties inherited from trembita module. +- Define the methods that contains the logic that expose third party library logic you want to use. + +One example of usage would be: + +```js +const clientOptions = { + headers: { + header1: 'xxx', + header2: 'yyy' + }, + endpoint: 'http://serviceapi.com' +}; + +const MyAPIClient = class MyAPIClient extends Trembita { + constructor(options) { + super(...arguments); + + this.getData = paramsQueryString => { + const params = { + url: `api/path/`, + qs: paramsQueryString, + expectedCodes: [200, 401, 403, 404], + headers: { + 'header1': this.header1, + 'header2': this.header2 + } + }; + return this.request(params); + } + } +} + +const client = new MyAPIClient(clientOptions); +``` + ## Contribute See [the contribute file](CONTRIBUTING.md)!