1
1
[ ![ 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 )
2
3
[ ![ Build Status] ( https://travis-ci.org/cloudevents/sdk-javascript.svg?branch=master )] ( https://travis-ci.org/cloudevents/sdk-javascript )
3
4
4
5
# sdk-javascript
5
- Javascript SDK for CloudEvents
6
6
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 " >
8
10
9
11
## Installation
10
12
11
13
This CloudEvents SDK requires nodejs 6.11+
12
14
13
15
### Nodejs
14
16
15
- ```
17
+ ``` sh
16
18
npm install cloudevents-sdk
17
19
```
18
20
## Specification Support
19
21
20
22
These are the supported specifications by this version.
21
23
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 |
27
30
28
31
## How to use
29
32
@@ -39,7 +42,7 @@ Cloudevent(spec, format);
39
42
40
43
```
41
44
42
- ### How to construct instances?
45
+ ### Usage
43
46
44
47
``` js
45
48
var Cloudevent = require (" cloudevents-sdk" );
@@ -59,7 +62,8 @@ cloudevent01
59
62
.source (" urn:event:from:myapi/resourse/123" );
60
63
61
64
/*
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
63
67
*/
64
68
cloudevent01
65
69
.eventTypeVersion (" 1.0" );
@@ -69,7 +73,7 @@ cloudevent01
69
73
* - Spec 0.2
70
74
* - JSON Format 0.1
71
75
*/
72
- var cloudevent02 = new Cloudevent (Cloudevent .specs [' 0.2' ]);
76
+ var cloudevent02 = new Cloudevent (Cloudevent .specs [" 0.2" ]);
73
77
74
78
/*
75
79
* Different specs, but the same API.
@@ -80,23 +84,27 @@ cloudevent02
80
84
81
85
```
82
86
83
- ### How to get the formatted payload?
87
+ #### Formatting
84
88
85
89
``` js
86
90
var Cloudevent = require (" cloudevents-sdk" );
87
91
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" );
91
99
92
100
/*
93
- * Format the payload and return it.
101
+ * Format the payload and return it
94
102
*/
95
103
var formatted = cloudevent .format ();
96
104
97
105
```
98
106
99
- ### How to emit an event?
107
+ #### Emitting
100
108
101
109
``` js
102
110
var Cloudevent = require (" cloudevents-sdk" );
@@ -108,12 +116,12 @@ var cloudevent = new Cloudevent()
108
116
109
117
// The binding configuration using POST
110
118
var config = {
111
- method: ' POST' ,
112
- url : ' https://mywebhook .com'
119
+ method: " POST" ,
120
+ url : " https://myserver .com"
113
121
};
114
122
115
123
// The binding instance
116
- var binding = Cloudevent .bindings [' http-structured0.1' ](config);
124
+ var binding = Cloudevent .bindings [" http-structured0.1" ](config);
117
125
118
126
// Emit the event using Promise
119
127
binding .emit (cloudevent)
@@ -134,45 +142,20 @@ binding.emit(cloudevent)
134
142
├── lib
135
143
│ ├── bindings
136
144
│ │ └── http
137
- │ │ └── structured_0_1.js
138
145
│ ├── cloudevent.js
139
146
│ ├── format
140
- │ │ └── json_0_1.js
141
147
│ └── specs
142
- │ ├── spec_0_1.js
143
- │ └── spec_0_2.js
144
148
├── LICENSE
145
149
├── package.json
146
150
├── README.md
147
- └── test
148
- ├── cloudevent_spec_0_1.js
149
- ├── cloudevent_spec_0_2.js
150
- └── http_binding_0_1.js
151
151
```
152
152
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
176
159
177
160
## Unit Testing
178
161
0 commit comments