11[ ![ Codacy Badge] ( https://api.codacy.com/project/badge/Grade/bd66e7c52002481993cd6d610534b0f7 )] ( https://www.codacy.com/app/fabiojose/sdk-javascript?utm_source=github.com& ; utm_medium=referral& ; utm_content=cloudevents/sdk-javascript& ; utm_campaign=Badge_Grade )
2+ [ ![ Codacy Badge] ( https://api.codacy.com/project/badge/Coverage/bd66e7c52002481993cd6d610534b0f7 )] ( https://www.codacy.com/app/fabiojose/sdk-javascript?utm_source=github.com& ; utm_medium=referral& ; utm_content=cloudevents/sdk-javascript& ; utm_campaign=Badge_Coverage )
23[ ![ Build Status] ( https://travis-ci.org/cloudevents/sdk-javascript.svg?branch=master )] ( https://travis-ci.org/cloudevents/sdk-javascript )
34
45# sdk-javascript
5- Javascript SDK for CloudEvents
66
7- > This is a WIP
7+ Official CloudEvents' SDK for JavaScript.
8+
9+ <img src =" https://raw.githubusercontent.com/cncf/artwork/master/cloudevents/horizontal/color/cloudevents-horizontal-color.png " width =" 300 " height =" 58 " alt =" CloudEvents logo " >
810
911## Installation
1012
1113This CloudEvents SDK requires nodejs 6.11+
1214
1315### Nodejs
1416
15- ```
17+ ``` sh
1618npm install cloudevents-sdk
1719```
1820## Specification Support
1921
2022These are the supported specifications by this version.
2123
22- | ** Specifications** | ** v0.1** | ** v0.2** |
23- | ----------------------------| ----------| ----------|
24- | CloudEvents | yes | yes |
25- | HTTP Transport Binding | yes | yes |
26- | JSON Event Format | yes | yes |
24+ | ** Specifications** | ** v0.1** | ** v0.2** |
25+ | ---------------------------------------| ----------| ----------|
26+ | CloudEvents | yes | yes |
27+ | HTTP Transport Binding - Structured | yes | yes |
28+ | HTTP Transport Binding - Binary | yes | yes |
29+ | JSON Event Format | yes | yes |
2730
2831## How to use
2932
@@ -39,7 +42,7 @@ Cloudevent(spec, format);
3942
4043```
4144
42- ### How to construct instances?
45+ ### Usage
4346
4447``` js
4548var Cloudevent = require (" cloudevents-sdk" );
@@ -59,7 +62,8 @@ cloudevent01
5962 .source (" urn:event:from:myapi/resourse/123" );
6063
6164/*
62- * Backward compatibility by injecting methods from spec implementation to Cloudevent
65+ * Backward compatibility to spec 0.1 by injecting methods from spec implementation
66+ * to Cloudevent
6367 */
6468cloudevent01
6569 .eventTypeVersion (" 1.0" );
@@ -69,7 +73,7 @@ cloudevent01
6973 * - Spec 0.2
7074 * - JSON Format 0.1
7175 */
72- var cloudevent02 = new Cloudevent (Cloudevent .specs [' 0.2' ]);
76+ var cloudevent02 = new Cloudevent (Cloudevent .specs [" 0.2" ]);
7377
7478/*
7579 * Different specs, but the same API.
@@ -80,23 +84,27 @@ cloudevent02
8084
8185```
8286
83- ### How to get the formatted payload?
87+ #### Formatting
8488
8589``` js
8690var Cloudevent = require (" cloudevents-sdk" );
8791
88- var cloudevent = new Cloudevent ()
89- .type (" com.github.pull.create" )
90- .source (" urn:event:from:myapi/resourse/123" );
92+ /*
93+ * Creates an instance with default spec and format
94+ */
95+ var cloudevent =
96+ new Cloudevent ()
97+ .type (" com.github.pull.create" )
98+ .source (" urn:event:from:myapi/resourse/123" );
9199
92100/*
93- * Format the payload and return it.
101+ * Format the payload and return it
94102 */
95103var formatted = cloudevent .format ();
96104
97105```
98106
99- ### How to emit an event?
107+ #### Emitting
100108
101109``` js
102110var Cloudevent = require (" cloudevents-sdk" );
@@ -108,12 +116,12 @@ var cloudevent = new Cloudevent()
108116
109117// The binding configuration using POST
110118var config = {
111- method: ' POST' ,
112- url : ' https://mywebhook .com'
119+ method: " POST" ,
120+ url : " https://myserver .com"
113121};
114122
115123// The binding instance
116- var binding = Cloudevent .bindings [' http-structured0.1' ](config);
124+ var binding = Cloudevent .bindings [" http-structured0.1" ](config);
117125
118126// Emit the event using Promise
119127binding .emit (cloudevent)
@@ -134,45 +142,20 @@ binding.emit(cloudevent)
134142├── lib
135143│ ├── bindings
136144│ │ └── http
137- │ │ └── structured_0_1.js
138145│ ├── cloudevent.js
139146│ ├── format
140- │ │ └── json_0_1.js
141147│ └── specs
142- │ ├── spec_0_1.js
143- │ └── spec_0_2.js
144148├── LICENSE
145149├── package.json
146150├── README.md
147- └── test
148- ├── cloudevent_spec_0_1.js
149- ├── cloudevent_spec_0_2.js
150- └── http_binding_0_1.js
151151```
152152
153- * ` index.js ` : library exports
154-
155- * ` lib/bindings ` : every binding implementation goes here
156-
157- * ` lib/bindings/http ` : every http binding implementation goes here
158-
159- * ` lib/bindings/http/structured_0_1.js ` : implementation of structured HTTP Binding
160-
161- * ` lib/cloudevent.js ` : implementation of Cloudevent, an interface
162-
163- * ` lib/format/ ` : every format implementation goes here
164-
165- * ` lib/format/json_0_1.js ` : implementation for JSON formatting [ version 0.1] ( https://github.com/cloudevents/spec/blob/v0.1/json-format.md )
166-
167- * ` lib/specs/ ` : every spec implementation goes here
168-
169- * ` lib/specs/spec_0_1.js ` : implementation for spec [ version 0.1] ( https://github.com/cloudevents/spec/blob/v0.1/spec.md )
170-
171- * ` lib/specs/spec_0_2.js ` : implementation for spec [ version 0.2] ( https://github.com/cloudevents/spec/blob/v0.2/spec.md )
172-
173- * ` test/cloudevent_spec_0_1.js ` : unit testing for spec 0.1
174-
175- * ` test/cloudevent_spec_0_2.js ` : unit testing for spec 0.2
153+ - ` index.js ` : library exports
154+ - ` lib/bindings ` : every binding implementation goes here
155+ - ` lib/bindings/http ` : every http binding implementation goes here
156+ - ` lib/cloudevent.js ` : implementation of Cloudevent, an interface
157+ - ` lib/format/ ` : every format implementation goes here
158+ - ` lib/specs/ ` : every spec implementation goes here
176159
177160## Unit Testing
178161
0 commit comments