docs: add TS examples for CloudEvent usage (#461)

* docs: add TS examples for CloudEvent usage

Co-authored-by: Lance Ball <lball@redhat.com>
This commit is contained in:
David Pereira 2022-01-26 21:54:49 +00:00 committed by GitHub
parent ae8fa799af
commit c603831e93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -132,6 +132,29 @@ const ce = new CloudEvent({...});
const ce2 = ce.cloneWith({extension: "Value"});
```
You can create a `CloudEvent` object in many ways, for example, in TypeScript:
```js
import { CloudEvent, CloudEventV1, CloudEventV1Attributes } from "cloudevents";
const ce: CloudEventV1<string> = {
specversion: '1.0',
source: '/some/source',
type: 'example',
id: '1234'
};
const event = new CloudEvent(ce);
const ce2: CloudEventV1Attributes<string> = {
specversion: '1.0',
source: '/some/source',
type: 'example',
};
const event2 = new CloudEvent(ce2);
const event3 = new CloudEvent({
source: '/some/source',
type: 'example',
});
```
### Example Applications
There are a few trivial example applications in