|
| 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 | +``` |
0 commit comments