Skip to content

1 line parse CloudEvent from HTTP Request #261

Closed

Description

@grant

Like Ruby and some other SDKs, it should be 1 line to extract a CloudEvent JSON object from a HTTP request.

  • 1 line/function for HTTP -> CloudEvent object
  • No constructors needed. No new (unless we're saying new CloudEvent).

Expected

import { Receiver } from "cloudevents";

const event = Receiver.accept(headers, body);

Actual

import { Receiver } from "cloudevents";

const receiver = new Receiver();
const event = receiver.accept(headers, body);

Full Example

For example, this should work in Express:

import { Receiver } from "cloudevents";

const myFunction = (req, res) => {
  const event = Receiver.accept(req.headers, req.body);
  console.log(event.type);
};

This should be updated in the README (currently CloudEvent is unused).


I don't know what the receiver object is really for. Maybe historical. Should be pretty lightweight, right?
Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions