Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 2.19 KB

ce-go-template-http-client-mapper.md

File metadata and controls

35 lines (27 loc) · 2.19 KB

ce-go-template-http-client-mapper

ce-go-template-http-client-mapper

configuration

Name Default Description
VERBOSE true if true you get an extensive log output
REQUEST_TEMPLATE Go template for the transformation of the incoming event to a HTTP-Request in form of RFC2616. Payload of the incoming event is available under data.
RESPONSE_TEMPLATE `{{ .httpresponse.body toJson }}`
HTTP_JSON_BODY true if true marshalls the response payload to a data structure available as httpresponse.body
CE_SOURCE https://github.com/alitari/ce-go-template Cloudevent Source
CE_TYPE com.github.alitari.ce-go-template.mapper Cloudevent Type
K_SINK An adressable K8s resource. see Sinkbinding
CE_PORT 8080 server port

available elements in RESONSE_TEMPLATE

  • inputce: payload of the incoming event
  • httpresponse.header: response header
  • httpresponse.status: response status
  • httpresponse.statusCode: response status code as int
  • httpresponse.body: response body as struct if payload is json and HTTP_JSON_BODY is true, string otherwise

examples

use external service to find out the gender of a name

REQUEST_TEMPLATE="GET https://api.genderize.io?name={{ .data.name }} HTTP/1.1"$'\n'"content-type: application/json"$'\n'$'\n' \
RESPONSE_TEMPLATE='{ "name": {{ .inputce.data.name | quote }}, "gender": {{ .httpresponse.body.gender | quote }} }' go run cmd/http-client-mapper/main.go
# in a new shell
http POST localhost:8080 "content-type: application/json" "ce-specversion: 1.0" "ce-source: http-command" "ce-type: example" "ce-id: 123-abc" name=Daniela