From c53781489c07baea5e1bc228171d17b6e8f4beeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 9 Nov 2018 15:25:54 -0200 Subject: [PATCH] API Documentation --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9575c43..818d1ed 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,57 @@ Javascript SDK for CloudEvents * `test/cloudevent_spec_0_2.js`: unit testing for spec 0.2 -# How to use +# The API + +## `Cloudevent` class ```js +/* + * Format the payload and return it. + */ +Cloudevent.format() + +/* + * Format the payload as String. + */ +Cloudevent.toString() + +``` + +## `Formatter` class + +```js + +/* + * Format the Cloudevent payload argument and return an Object. + */ +Object Formatter.format(payload) + +/* + * Format the Cloudevent payload as String. + */ +String Formatter.toString(payload) + +``` + +# How to use + +The `Cloudevent` constructor arguments. + +```js + +/* + * spec : if is null, set the spec 0.1 impl + * format: if is null, set the JSON Format 0.1 impl + */ +Cloudevent(spec, format); + +``` + +## How to construct instances? + +```js /* * Constructs a default instance with: * - Spec 0.1 @@ -78,6 +125,22 @@ cloudevent02 .type("com.github.pull.create") .source("urn:event:from:myapi/resourse/123"); +var cloudevent = new Cloudevent + +``` + +## How to get the formatted payload? + +```js +var cloudevent = new Cloudevent() + .type("com.github.pull.create") + .source("urn:event:from:myapi/resourse/123"); + +/* + * Format the payload and return it. + */ +var formatted = cloudevent.format(); + ``` > See how to implement the method injection [here](lib/specs/spec_0_1.js#L17)