Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: introduce Message, Serializer, Deserializer and Binding interfaces #324

Merged
merged 12 commits into from
Aug 26, 2020

Conversation

lance
Copy link
Member

@lance lance commented Aug 22, 2020

Proposed Changes

This PR introduces the Message, Serializer and Deserializer, and Binding interfaces used to convert a CloudEvent into a Message that can be sent across a transport protocol. The first protocol implemented for this is HTTP, and some of the functionality formerly in src/transport/http has been simplified, reduced and/or moved to /src/messages/http.

Test for V1 events are in place. Conformance tests have been modified to use these new interfaces vs. the HTTP Receiver class.

Example usage

In an express.js application, simply create a Message using the incoming request headers and body. Then call HTTP.toEvent(message).

app.post("/", (req, res) => {
  const message = {
    headers: req.headers,
    body: req.body
  };

  const event = HTTP.toEvent(message);
});

Of course, this can be inlined as: HTTP.toEvent({ headers: req.headers, body: req.body });.

Sending a Message should also be straightforward. Convert a CloudEvent to a message, and send it using Axios or any other HTTP transport library that allows setting headers and body.

const message = HTTP.binary(event);
axios.post({
  url: 'https://event.receiver.com',
  headers: message.headers,
  body: message.body
});

@lance lance added type/enhancement New feature or request module/transport/http Issues related to the HTTP transport protocol implementation module/lib Related to the main source code version/4.x Issues related to the 4.0 release of this library labels Aug 22, 2020
@lance lance requested a review from a team August 22, 2020 20:09
@lance lance self-assigned this Aug 22, 2020
This commit introduces the Message, Serializer and Deserializer, and Binding
interfaces used to convert a CloudEvent into a Message that can be sent across
a transport protocol. The first protocol implemented for this is HTTP, and some
of the functionality formerly in src/transport/http has been simplified,
reduced and/or moved to /src/messages/http.

Test for V1 events are in place. Conformance tests have been modified to use
these new interfaces vs. the HTTP Receiver class.

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance changed the title Lance/ce next Introduce Message, Serializer, Deserializer and Binding interfaces Aug 22, 2020
@lance lance changed the title Introduce Message, Serializer, Deserializer and Binding interfaces feat: introduce Message, Serializer, Deserializer and Binding interfaces Aug 22, 2020
lance added 2 commits August 23, 2020 17:36
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance marked this pull request as draft August 24, 2020 14:47
Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist lholmquist added the version/3.x Issues related to the 3.0 release of this library label Aug 24, 2020
lance added 3 commits August 24, 2020 13:59
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance marked this pull request as ready for review August 24, 2020 18:17
@lance
Copy link
Member Author

lance commented Aug 24, 2020

@cloudevents/sdk-javascript-maintainers this should be ready now with both v1 and v03 of the spec being tested. PTAL

Fixes: #295

Signed-off-by: Lance Ball <lball@redhat.com>
@lance lance mentioned this pull request Aug 24, 2020
Copy link
Contributor

@lholmquist lholmquist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the removed tests, shouldn't we keep them until 4.0.0 to make sure we didn't break anything for the current usage?

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Aug 25, 2020

@lholmquist I can revert those tests if you think they are needed. My problem with them is that they were not really integration tests, as they were testing implementation details and not the public facing API. Coverage doesn't actually go down when these are removed!

Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist
Copy link
Contributor

they were testing implementation details and not the public facing API.

Ok, then it is probably fine to remove them

Signed-off-by: Lance Ball <lball@redhat.com>
@lance
Copy link
Member Author

lance commented Aug 26, 2020

@lholmquist I think this is probably ready to land, but I'm not sure if your comments are an implicit approval or not.

@lholmquist
Copy link
Contributor

oh sorry, i think i forgot to press the approve button

@lance lance merged commit f3953a9 into main Aug 26, 2020
@lance lance deleted the lance/ce-next branch August 26, 2020 22:26
lance added a commit that referenced this pull request Sep 3, 2020
…ces (#324)

* lib(messages): Implement a 4.0 Messages and other supporting interfaces

This commit introduces the Message, Serializer and Deserializer, and Binding
interfaces used to convert a CloudEvent into a Message that can be sent across
a transport protocol. The first protocol implemented for this is HTTP, and some
of the functionality formerly in src/transport/http has been simplified,
reduced and/or moved to /src/messages/http.

Test for V1 and V3 events are in place. Conformance tests have been modified to use
these new interfaces vs. the HTTP Receiver class.

Signed-off-by: Lance Ball <lball@redhat.com>
lance added a commit that referenced this pull request Sep 11, 2020
…ces (#324)

* lib(messages): Implement a 4.0 Messages and other supporting interfaces

This commit introduces the Message, Serializer and Deserializer, and Binding
interfaces used to convert a CloudEvent into a Message that can be sent across
a transport protocol. The first protocol implemented for this is HTTP, and some
of the functionality formerly in src/transport/http has been simplified,
reduced and/or moved to /src/messages/http.

Test for V1 and V3 events are in place. Conformance tests have been modified to use
these new interfaces vs. the HTTP Receiver class.

Signed-off-by: Lance Ball <lball@redhat.com>
@lholmquist lholmquist mentioned this pull request Dec 11, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
module/lib Related to the main source code module/transport/http Issues related to the HTTP transport protocol implementation type/enhancement New feature or request version/3.x Issues related to the 3.0 release of this library version/4.x Issues related to the 4.0 release of this library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding More Transport Protocols - A Proposal isCloudEvent Function
2 participants