# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/request.cue
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  annotations:
    custom.definition.oam.dev/category: External Integration
    definition.oam.dev/alias: ""
    definition.oam.dev/description: Send request to the url
  name: request
  namespace: {{ include "systemDefinitionNamespace" . }}
spec:
  schematic:
    cue:
      template: |
        import (
        	"vela/op"
        	"vela/http"
        	"encoding/json"
        )

        req: http.#HTTPDo & {
        	$params: {
        		method: parameter.method
        		url:    parameter.url
        		request: {
        			if parameter.body != _|_ {
        				body: json.Marshal(parameter.body)
        			}
        			if parameter.header != _|_ {
        				header: parameter.header
        			}
        		}
        	}
        }

        wait: op.#ConditionalWait & {
        	continue: req.$returns != _|_
        	message?: "Waiting for response from \(parameter.url)"
        }

        fail: op.#Steps & {
        	if req.$returns.statusCode > 400 {
        		requestFail: op.#Fail & {
        			message: "request of \(parameter.url) is fail: \(req.$returns.statusCode)"
        		}
        	}
        }

        response: json.Unmarshal(req.$returns.body)

        parameter: {
        	url:    string
        	method: *"GET" | "POST" | "PUT" | "DELETE"
        	body?: {...}
        	header?: [string]: string
        }

