@@ -74,39 +74,47 @@ structured events, add that string as a parameter to `emitter.sent()`.
7474``` js
7575const { CloudEvent , HTTPEmitter } = require (" cloudevents-sdk" );
7676
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+ });
7981const event = new CloudEvent ()
8082 .type (type)
8183 .source (source)
8284 .time (new Date ())
8385 .data (data)
8486
8587// 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" })
8794 .then ((response ) => {
8895 // handle the response
89- })
90- .catch (console .error );
96+ }).catch (console .error );
9197
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 " })
94100 .then ((response ) => {
95101 // handle the response
96- })
97- .catch (console .error );
102+ }).catch (console .error );
98103
99104// Sending a v0.3 event works the same, just let the emitter know when
100105// 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+ });
102110
103111// 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 )
106115 .then ((response ) => {
107116 // handle the response
108- })
109- .catch (console .error );
117+ }).catch (console .error );
110118
111119```
112120
0 commit comments