webhook

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPProcessor added in v0.13.4

type HTTPProcessor struct {
	sdk.UnimplementedProcessor
	// contains filtered or unexported fields
}
Example
p := NewHTTPProcessor(conduit_log.Nop())

srv := newTestServer()
// Stop the server on return from the function.
defer srv.Close()

exampleutil.RunExample(p, exampleutil.Example{
	Summary: `Send a request to an HTTP server`,
	Description: `
This example shows how to use the HTTP processor to send a record's ` + "`.Payload.After`" + ` field as a string to a dummy
HTTP server that replies back with a greeting.

The record's ` + "`.Payload.After`" + ` is overwritten with the response. Additionally, the example shows how to set a request
header and how to store the value of the HTTP response's code in the metadata field ` + "`http_status`" + `.`,
	Config: config.Config{
		"request.url":          srv.URL,
		"request.body":         `{{ printf "%s" .Payload.After }}`,
		"response.status":      `.Metadata["http_status"]`,
		"headers.content-type": "application/json",
	},
	Have: opencdc.Record{
		Operation: opencdc.OperationUpdate,
		Position:  opencdc.Position("pos-1"),
		Payload: opencdc.Change{
			After: opencdc.RawData("world"),
		},
	},
	Want: sdk.SingleRecord{
		Operation: opencdc.OperationUpdate,
		Position:  opencdc.Position("pos-1"),
		Metadata: map[string]string{
			"http_status": "200",
		},
		Payload: opencdc.Change{
			After: opencdc.RawData("hello, world"),
		},
	},
})
Output:

processor transformed record:
--- before
+++ after
@@ -1,10 +1,12 @@
 {
   "position": "cG9zLTE=",
   "operation": "update",
-  "metadata": null,
+  "metadata": {
+    "http_status": "200"
+  },
   "key": null,
   "payload": {
     "before": null,
-    "after": "world"
+    "after": "hello, world"
   }
 }
Example (DynamicURL)
p := NewHTTPProcessor(conduit_log.Nop())

srv := newTestServer()
// Stop the server on return from the function.
defer srv.Close()

exampleutil.RunExample(p, exampleutil.Example{
	Summary: `Send a request to an HTTP server with a dynamic URL`,
	Description: `
This example shows how to use the HTTP processor to use a record's ` + "`.Payload.After.name`" + ` field in the URL path,
send it to a dummy HTTP server, and get a greeting with the name back.

The response will be written under the record's ` + "`.Payload.After.response`.",
	Config: config.Config{
		"request.url":   srv.URL + "/{{.Payload.After.name}}",
		"response.body": ".Payload.After.response",
	},
	Have: opencdc.Record{
		Operation: opencdc.OperationCreate,
		Position:  opencdc.Position("pos-1"),
		Payload: opencdc.Change{
			After: opencdc.StructuredData{
				"name": "foo",
			},
		},
	},
	Want: sdk.SingleRecord{
		Operation: opencdc.OperationCreate,
		Position:  opencdc.Position("pos-1"),
		Payload: opencdc.Change{
			After: opencdc.StructuredData{
				"name":     "foo",
				"response": []byte("hello, foo!"),
			},
		},
	},
})
Output:

processor transformed record:
--- before
+++ after
@@ -1,12 +1,13 @@
 {
   "position": "cG9zLTE=",
   "operation": "create",
   "metadata": null,
   "key": null,
   "payload": {
     "before": null,
     "after": {
-      "name": "foo"
+      "name": "foo",
+      "response": "aGVsbG8sIGZvbyE="
     }
   }
 }

func NewHTTPProcessor

func NewHTTPProcessor(l log.CtxLogger) *HTTPProcessor

func (*HTTPProcessor) Configure added in v0.13.4

func (p *HTTPProcessor) Configure(ctx context.Context, c config.Config) error

func (*HTTPProcessor) Process added in v0.13.4

func (p *HTTPProcessor) Process(ctx context.Context, records []opencdc.Record) []sdk.ProcessedRecord

func (*HTTPProcessor) Specification added in v0.13.4

func (p *HTTPProcessor) Specification() (sdk.Specification, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL