Skip to content

Commit 9acac52

Browse files
committed
chore: add a transition guide. fixes cloudevents#360
Signed-off-by: Lucas Holmquist <lholmqui@redhat.com>
1 parent 9f86cfd commit 9acac52

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

API_TRANSITION_GUIDE.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Deprecated API Transition Guide
2+
3+
When API's are deprecated, the following guide will show how to transition from removed API's to the new ones
4+
5+
6+
### Upgrading From 3.x to 4.0
7+
8+
In the 3.2.0 release, a few API's were set to be deprecated in the 4.0 release. With the release of 4.0.0, those API's have been removed.
9+
10+
#### Receiever
11+
12+
The `Receiver` class has been removed.
13+
14+
`Receiver.accept` should be transitioned to `HTTP.toEvent`
15+
16+
#### Emitter
17+
18+
The `Emitter` class has been removed.
19+
20+
`Emit.send` should be transitioned to `HTTP.binary` for binary events and `HTTP.structured` for structured events
21+
22+
`Emit.send` would use axios to emit the events. Since this now longer available, you are free to choose your own transport protocol.
23+
24+
So for axios, it might look something like this:
25+
26+
```js
27+
const axios = require('axios').default;
28+
const { HTTP } = require("cloudevents");
29+
30+
31+
const ce = new CloudEvent({ type, source, data })
32+
const message = HTTP.binary(ce); // Or HTTP.structured(ce)
33+
34+
axios({
35+
method: 'post',
36+
url: '...',
37+
data: message.body,
38+
headers: message.headers,
39+
});
40+
```
41+
42+
You may also use the `emitterFor()` function as a convenience.
43+
44+
```js
45+
const axios = require('axios').default;
46+
const { emitterFor, Mode } = require("cloudevents");
47+
48+
function sendWithAxios(message) {
49+
// Do what you need with the message headers
50+
// and body in this function, then send the
51+
// event
52+
axios({
53+
method: 'post',
54+
url: '...',
55+
data: message.body,
56+
headers: message.headers,
57+
});
58+
}
59+
60+
const emit = emitterFor(sendWithAxios, { mode: Mode.BINARY });
61+
emit(new CloudEvent({ type, source, data }));
62+
```

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ There are a few trivial example applications in
138138
[the examples folder](https://github.com/cloudevents/sdk-javascript/tree/main/examples).
139139
There you will find Express.js, TypeScript and Websocket examples.
140140

141+
142+
### API Transition Guide
143+
144+
[Guide Link](./API_TRANSITION_GUIDE.md)
145+
141146
## Supported specification features
142147

143148
| Core Specification | [v0.3](https://github.com/cloudevents/spec/blob/v0.3/spec.md) | [v1.0](https://github.com/cloudevents/spec/blob/v1.0/spec.md) |

0 commit comments

Comments
 (0)