Skip to content

Commit c603831

Browse files
BOLT04lance
andauthored
docs: add TS examples for CloudEvent usage (#461)
* docs: add TS examples for CloudEvent usage Co-authored-by: Lance Ball <lball@redhat.com>
1 parent ae8fa79 commit c603831

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ const ce = new CloudEvent({...});
132132
const ce2 = ce.cloneWith({extension: "Value"});
133133
```
134134

135+
You can create a `CloudEvent` object in many ways, for example, in TypeScript:
136+
137+
```js
138+
import { CloudEvent, CloudEventV1, CloudEventV1Attributes } from "cloudevents";
139+
const ce: CloudEventV1<string> = {
140+
specversion: '1.0',
141+
source: '/some/source',
142+
type: 'example',
143+
id: '1234'
144+
};
145+
const event = new CloudEvent(ce);
146+
const ce2: CloudEventV1Attributes<string> = {
147+
specversion: '1.0',
148+
source: '/some/source',
149+
type: 'example',
150+
};
151+
const event2 = new CloudEvent(ce2);
152+
const event3 = new CloudEvent({
153+
source: '/some/source',
154+
type: 'example',
155+
});
156+
```
157+
135158
### Example Applications
136159

137160
There are a few trivial example applications in

0 commit comments

Comments
 (0)