Skip to content

Commit 038c786

Browse files
committed
Document the use of unmarshaller
Signed-off-by: Fabio José <[email protected]>
1 parent a9962d7 commit 038c786

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

README.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,41 @@ binding.emit(cloudevent)
168168
console.error(err);
169169
});
170170
```
171-
#### Receiving Events Using Express
171+
#### Receiving Events
172172

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)__
175177

176178
```js
179+
// some parts weres removed //
180+
177181
var Unmarshaller02 = require("cloudevents-sdk/http/unmarshaller/v02");
178182

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+
179206
```
180207

181208
## Repository Structure

0 commit comments

Comments
 (0)