Document the use of unmarshaller

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-06-25 11:17:37 -03:00
parent a9962d76ec
commit 038c786e6c
1 changed files with 30 additions and 3 deletions

View File

@ -168,14 +168,41 @@ binding.emit(cloudevent)
console.error(err);
});
```
#### Receiving Events Using Express
#### Receiving Events
See how to listen to events using
[express](https://github.com/expressjs/express).
You can choose any http framework for port binding, but use the Unmarshaller
to process the HTTP Payload and HTTP Headers to extract the CloudEvents.
__Checkout the full working example [here](./examples/express-ex)__
```js
// some parts weres removed //
var Unmarshaller02 = require("cloudevents-sdk/http/unmarshaller/v02");
// some parts were removed //
app.post('/', function (req, res) {
try {
// Using the Unmarshaller
var cloudevent =
unmarshaller.unmarshall(req.body, req.headers);
// pretty print
console.log("Event Accepted:");
res.status(201)
.send("Event Accepted");
}catch(e) {
console.error(e);
res.status(400)
.header("Content-Type", "application/json")
.send(JSON.stringify(e));
}
});
```
## Repository Structure