docs: improve readme receiver example (#309)
Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
This commit is contained in:
parent
08bf15d161
commit
d590e3a007
14
README.md
14
README.md
|
@ -34,14 +34,14 @@ You can choose almost any popular web framework for port binding. Use an
|
||||||
binary and structured events in either the 1.0 or 0.3 protocol formats.
|
binary and structured events in either the 1.0 or 0.3 protocol formats.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const {
|
const app = require("express")();
|
||||||
CloudEvent,
|
const {Receiver} = require("cloudevents");
|
||||||
Receiver
|
|
||||||
} = require("cloudevents");
|
|
||||||
|
|
||||||
// body and headers come from an incoming HTTP request, e.g. express.js
|
app.post("/", (req, res) => {
|
||||||
const receivedEvent = Receiver.accept(req.headers, req.body);
|
// body and headers come from an incoming HTTP request, e.g. express.js
|
||||||
console.log(receivedEvent);
|
const receivedEvent = Receiver.accept(req.headers, req.body);
|
||||||
|
console.log(receivedEvent);
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Emitting Events
|
#### Emitting Events
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
/* eslint-disable no-console */
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const { Receiver } = require("cloudevents");
|
const {Receiver} = require("cloudevents");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const receiver = new Receiver();
|
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
let data = "";
|
let data = "";
|
||||||
|
@ -20,7 +19,7 @@ app.use((req, res, next) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/", function (req, res) {
|
app.post("/", (req, res) => {
|
||||||
console.log("HEADERS", req.headers);
|
console.log("HEADERS", req.headers);
|
||||||
console.log("BODY", req.body);
|
console.log("BODY", req.body);
|
||||||
|
|
||||||
|
@ -34,6 +33,6 @@ app.post("/", function (req, res) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(3000, function () {
|
app.listen(3000, () => {
|
||||||
console.log("Example app listening on port 3000!");
|
console.log("Example app listening on port 3000!");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue