diff --git a/lib/bindings/http/structured_0_2.js b/lib/bindings/http/structured_0_2.js new file mode 100644 index 0000000..65c6530 --- /dev/null +++ b/lib/bindings/http/structured_0_2.js @@ -0,0 +1,23 @@ +var axios = require("axios"); + +function HTTPStructured(configuration){ + this.config = configuration; + + this.config["headers"] = { + "Content-Type":"application/cloudevents+json; charset=utf-8" + }; +} + +HTTPStructured.prototype.emit = function(cloudevent){ + + // Create new request object + var _config = JSON.parse(JSON.stringify(this.config)); + + // Set the cloudevent payload + _config["data"] = cloudevent.format(); + + // Return the Promise + return axios.request(_config); +}; + +module.exports = HTTPStructured; diff --git a/lib/cloudevent.js b/lib/cloudevent.js index 73070e6..0cf5e8c 100644 --- a/lib/cloudevent.js +++ b/lib/cloudevent.js @@ -2,6 +2,7 @@ var Spec01 = require("./specs/spec_0_1.js"); var Spec02 = require("./specs/spec_0_2.js"); var JSONFormatter01 = require("./formats/json_0_1.js"); var HTTPStructured01 = require("./bindings/http/structured_0_1.js"); +var HTTPStructured02 = require("./bindings/http/structured_0_2.js"); var HTTPBinary01 = require("./bindings/http/binary_0_1.js"); var HTTPBinary02 = require("./bindings/http/binary_0_2.js"); @@ -122,6 +123,7 @@ Cloudevent.formats = { Cloudevent.bindings = { "http-structured" : HTTPStructured01, "http-structured0.1" : HTTPStructured01, + "http-structured0.2" : HTTPStructured02, "http-binary0.1" : HTTPBinary01, "http-binary0.2" : HTTPBinary02 }; diff --git a/test/http_binding_0_2.js b/test/http_binding_0_2.js index ae167ee..16086a9 100644 --- a/test/http_binding_0_2.js +++ b/test/http_binding_0_2.js @@ -15,7 +15,7 @@ const data = { foo: "bar" }; -const Structured01 = Cloudevent.bindings["http-structured0.1"]; +const Structured02 = Cloudevent.bindings["http-structured0.2"]; const Binary02 = Cloudevent.bindings["http-binary0.2"]; var cloudevent = @@ -27,14 +27,12 @@ var cloudevent = .schemaurl(schemaurl) .data(data); -cloudevent.eventTypeVersion("1.0.0"); - var httpcfg = { method : "POST", url : webhook + "/json" }; -var httpstructured01 = new Structured01(httpcfg); +var httpstructured02 = new Structured02(httpcfg); var httpbinary02 = new Binary02(httpcfg); describe("HTTP Transport Binding - Version 0.2", () => { @@ -48,7 +46,7 @@ describe("HTTP Transport Binding - Version 0.2", () => { describe("Structured", () => { describe("JSON Format", () => { it("requires '" + contentType + "' Content-Type in the header", () => { - return httpstructured01.emit(cloudevent) + return httpstructured02.emit(cloudevent) .then((response) => { expect(response.config.headers["Content-Type"]) .to.equal(contentType); @@ -56,7 +54,7 @@ describe("HTTP Transport Binding - Version 0.2", () => { }); it("the request payload should be correct", () => { - return httpstructured01.emit(cloudevent) + return httpstructured02.emit(cloudevent) .then((response) => { expect(JSON.parse(response.config.data)) .to.deep.equal(cloudevent.format());