8000 Document the binding usage · pengsrc/sdk-javascript@ceb5c45 · GitHub
[go: up one dir, main page]

Skip to content

Commit ceb5c45

Browse files
committed
Document the binding usage
Signed-off-by: Fabio José <fabiojose@gmail.com>
1 parent 20c3296 commit ceb5c45

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ Every Spec class must implement these methods to work properly.
9494

9595
```js
9696

97+
/*
98+
* The constructor must receives the Cloudevent type.
99+
*/
100+
Spec(Cloudevent)
101+
97102
/*
98103
* Check the spec constraints, throwing an error if do not pass.
99104
*/
@@ -168,6 +173,35 @@ var formatted = cloudevent.format();
168173

169174
```
170175

176+
## Hot to emit the event?
177+
178+
```js
179+
// The event
180+
var cloudevent = new Cloudevent()
181+
.type("com.github.pull.create")
182+
.source("urn:event:from:myapi/resourse/123");
183+
184+
// The binding configuration using POST
185+
var config = {
186+
method: 'POST',
187+
url : 'https://mywebhook.com'
188+
};
189+
190+
// The binding instance
191+
var binding = Cloudevent.bindings['http-structured0.1'](config);
192+
193+
// Emit the event using Promise
194+
binding.emit(cloudevent)
195+
.then(response => {
196+
// Treat the response
197+
console.log(response.data);
198+
199+
}).catch(err => {
200+
// Treat the error
201+
console.error(err);
202+
});
203+
```
204+
171205
> See how to implement the method injection [here](lib/specs/spec_0_1.js#L17)
172206
>
173207
> Learn about [Builder Design Pattern](https://en.wikipedia.org/wiki/Builder_pattern)

0 commit comments

Comments
 (0)
0