File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -168,14 +168,41 @@ binding.emit(cloudevent)
168
168
console .error (err);
169
169
});
170
170
```
171
- #### Receiving Events Using Express
171
+ #### Receiving Events
172
172
173
- See how to listen to events using
174
- [ express] ( https://github.com/expressjs/express ) .
173
+ You can choose any http framework for port binding, but use the Unmarshaller
174
+ to process the HTTP Payload and HTTP Headers to extract the CloudEvents.
175
+
176
+ __ Checkout the full working example [ here] ( ./examples/express-ex ) __
175
177
176
178
``` js
179
+ // some parts weres removed //
180
+
177
181
var Unmarshaller02 = require (" cloudevents-sdk/http/unmarshaller/v02" );
178
182
183
+ // some parts were removed //
184
+
185
+ app .post (' /' , function (req , res ) {
186
+ try {
187
+ // Using the Unmarshaller
188
+ var cloudevent =
189
+ unmarshaller .unmarshall (req .body , req .headers );
190
+
191
+ // pretty print
192
+ console .log (" Event Accepted:" );
193
+
194
+ res .status (201 )
195
+ .send (" Event Accepted" );
196
+ }catch (e) {
197
+ console .error (e);
198
+
199
+ res .status (400 )
200
+ .header (" Content-Type" , " application/json" )
201
+ .send (JSON .stringify (e));
202
+ }
203
+ });
204
+
205
+
179
206
```
180
207
181
208
## Repository Structure
You can’t perform that action at this time.
0 commit comments