@@ -74,39 +74,47 @@ structured events, add that string as a parameter to `emitter.sent()`.
74
74
``` js
75
75
const { CloudEvent , HTTPEmitter } = require (" cloudevents-sdk" );
76
76
77
- // Without any parameters, this creates a v1 emitter
78
- const v1Emitter = new HTTPEmitter ();
77
+ // With only an endpoint URL, this creates a v1 emitter
78
+ const v1Emitter = new HTTPEmitter ({
79
+ url: " https://cloudevents.io/example"
80
+ });
79
81
const event = new CloudEvent ()
80
82
.type (type)
81
83
.source (source)
82
84
.time (new Date ())
83
85
.data (data)
84
86
85
87
// By default, the emitter will send binary events
86
- v1Emitter .send ({ url: " https://cloudevents.io/example" }, event )
88
+ v1Emitter .send (event ).then ((response ) => {
89
+ // handle the response
90
+ }).catch (console .error );
91
+
92
+ // To send a structured event, just add that as an option
93
+ v1Emitter .send (event , { mode: " structured" })
87
94
.then ((response ) => {
88
95
// handle the response
89
- })
90
- .catch (console .error );
96
+ }).catch (console .error );
91
97
92
- // To send a structured event, just add that as a parameter
93
- v1Emitter .send ({ url: " https://cloudevents.io/example " }, event , " structured " )
98
+ // To send an event to an alternate URL, add that as an option
99
+ v1Emitter .send (event , { url: " https://alternate.com/api " })
94
100
.then ((response ) => {
95
101
// handle the response
96
- })
97
- .catch (console .error );
102
+ }).catch (console .error );
98
103
99
104
// Sending a v0.3 event works the same, just let the emitter know when
100
105
// you create it that you are working with the 0.3 spec
101
- const v03Emitter = new HTTPEmitter (" 0.3" );
106
+ const v03Emitter = new HTTPEmitter ({
107
+ url: " https://cloudevents.io/example" ,
108
+ version: " 0.3"
109
+ });
102
110
103
111
// Again, the default is to send binary events
104
- // To send a structured event, add "structured" as a final parameter
105
- v3Emitter .send ({ url: " https://cloudevents.io/example" }, event )
112
+ // To send a structured event or to an alternate URL, provide those
113
+ // as parameters in a options object as above
114
+ v3Emitter .send (event )
106
115
.then ((response ) => {
107
116
// handle the response
108
- })
109
- .catch (console .error );
117
+ }).catch (console .error );
110
118
111
119
```
112
120
0 commit comments