-
Notifications
You must be signed in to change notification settings - Fork 69
Deprecated API transition guide. #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lholmquist
merged 1 commit into
cloudevents:main
from
lholmquist:360-transition-documentation-for-deprecated
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
## Deprecated API Transition Guide | ||
|
||
When APIs are deprecated, the following guide will show how to transition from removed APIs to the new ones | ||
|
||
|
||
### Upgrading From 3.x to 4.0 | ||
|
||
In the 3.2.0 release, a few APIs were set to be deprecated in the 4.0 release. With the release of 4.0.0, those APIs have been removed. | ||
|
||
#### Receiever | ||
|
||
The `Receiver` class has been removed. | ||
|
||
`Receiver.accept` should be transitioned to `HTTP.toEvent` | ||
|
||
Here is an example of what a `HTTP.toEvent` might look like using Express.js | ||
|
||
```js | ||
const app = require("express")(); | ||
const { HTTP } = require("cloudevents"); | ||
|
||
app.post("/", (req, res) => { | ||
// body and headers come from an incoming HTTP request, e.g. express.js | ||
const receivedEvent = HTTP.toEvent({ headers: req.headers, body: req.body }); | ||
console.log(receivedEvent); | ||
}); | ||
``` | ||
|
||
#### Emitter | ||
|
||
`Emit.send` should be transitioned to `HTTP.binary` for binary events and `HTTP.structured` for structured events | ||
|
||
`Emit.send` would use axios to emit the events. Since this now longer available, you are free to choose your own transport protocol. | ||
|
||
So for axios, it might look something like this: | ||
|
||
```js | ||
const axios = require('axios').default; | ||
const { HTTP } = require("cloudevents"); | ||
|
||
|
||
const ce = new CloudEvent({ type, source, data }) | ||
const message = HTTP.binary(ce); // Or HTTP.structured(ce) | ||
|
||
axios({ | ||
method: 'post', | ||
url: '...', | ||
data: message.body, | ||
headers: message.headers, | ||
}); | ||
``` | ||
|
||
You may also use the `emitterFor()` function as a convenience. | ||
|
||
```js | ||
const axios = require('axios').default; | ||
const { emitterFor, Mode } = require("cloudevents"); | ||
|
||
function sendWithAxios(message) { | ||
// Do what you need with the message headers | ||
// and body in this function, then send the | ||
// event | ||
axios({ | ||
method: 'post', | ||
url: '...', | ||
data: message.body, | ||
headers: message.headers, | ||
}); | ||
} | ||
|
||
const emit = emitterFor(sendWithAxios, { mode: Mode.BINARY }); | ||
emit(new CloudEvent({ type, source, data })); | ||
``` | ||
|
||
You may also use the `Emitter` singleton | ||
|
||
```js | ||
const axios = require("axios").default; | ||
const { emitterFor, Mode, CloudEvent, Emitter } = require("cloudevents"); | ||
|
||
function sendWithAxios(message) { | ||
// Do what you need with the message headers | ||
// and body in this function, then send the | ||
// event | ||
axios({ | ||
method: "post", | ||
url: "...", | ||
data: message.body, | ||
headers: message.headers, | ||
}); | ||
} | ||
|
||
const emit = emitterFor(sendWithAxios, { mode: Mode.BINARY }); | ||
// Set the emit | ||
Emitter.on("cloudevent", emit); | ||
|
||
... | ||
// In any part of the code will send the event | ||
new CloudEvent({ type, source, data }).emit(); | ||
|
||
// You can also have several listener to send the event to several endpoint | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.