Skip to content

Commit 81ba122

Browse files
docs: update cloudevent function docs to use declarative API (#381)
This commit updates our README and docs/ to use declarative function signatures for cloudevent functions.
1 parent 11d35b3 commit 81ba122

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,28 @@ It will be passed as an argument to your function when it receives a request.
228228
Note that your function must use the `cloudevent`-style function signature:
229229
230230
```js
231-
exports.helloCloudEvents = (cloudevent) => {
231+
const functions = require('@google-cloud/functions-framework');
232+
233+
functions.cloudEvent('helloCloudEvents', (cloudevent) => {
232234
console.log(cloudevent.specversion);
233235
console.log(cloudevent.type);
234236
console.log(cloudevent.source);
235237
console.log(cloudevent.subject);
236238
console.log(cloudevent.id);
237239
console.log(cloudevent.time);
238240
console.log(cloudevent.datacontenttype);
239-
};
241+
});
240242
```
241243
242-
To enable CloudEvents, set the signature type to `cloudevent`. By default, the HTTP signature will be used and automatic event unmarshalling will be disabled.
244+
To enable the CloudEvent functions, you must list the Functions Framework as a dependency in your `package.json`:
245+
246+
```json
247+
{
248+
"dependencies": {
249+
"@google-cloud/functions-framework": "~2.0.0-beta.1"
250+
}
251+
}
252+
```
243253
244254
Learn how to use CloudEvents in this [guide](docs/cloudevents.md).
245255

docs/cloudevents.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,35 @@ This guide shows you how to use the Functions Framework for local testing with:
77

88
## Local Testing of CloudEvents
99

10-
In your `package.json`, specify `--signature-type=cloudevent"` for the `functions-framework`:
10+
Install `@google-cloud/functions-framework` and list it as a dependency in your `package.json`:
1111

12-
```sh
13-
{
14-
"scripts": {
15-
"start": "functions-framework --target=helloCloudEvents --signature-type=cloudevent"
16-
}
17-
}
12+
```
13+
npm install --save @google-cloud/functions-framework
1814
```
1915

20-
Create an `index.js` file:
16+
Create an `index.js` file and declare your function:
2117

2218
```js
23-
exports.helloCloudEvents = (cloudevent) => {
19+
const functions = require('@google-cloud/functions-framework');
20+
21+
functions.cloudEvent('helloCloudEvents', (cloudevent) => {
2422
console.log(cloudevent.specversion);
2523
console.log(cloudevent.type);
2624
console.log(cloudevent.source);
2725
console.log(cloudevent.subject);
2826
console.log(cloudevent.id);
2927
console.log(cloudevent.time);
3028
console.log(cloudevent.datacontenttype);
29+
});
30+
```
31+
32+
Add a `package.json` script to start the Functions Framework and pass the name of your function as the `target`.
33+
34+
```sh
35+
{
36+
"scripts": {
37+
"start": "functions-framework --target=helloCloudEvents"
38+
}
3139
}
3240
```
3341

0 commit comments

Comments
 (0)