Versionen im Vergleich

Schlüssel

  • Diese Zeile wurde hinzugefügt.
  • Diese Zeile wurde entfernt.
  • Formatierung wurde geändert.

...

Beispiel einer kompletten Formular Definition

Codeblock
languagejs
themeDJango
titleBeispiel-Formularcollapsetrue
[
  {
    "type": "text",
    "key": "url",
    "label": "URL",
    "description": "URL des Servers an den Sie Einsätze übertragen möchten."
  },
  {
    "type": "checkbox",
    "key": "onlyTitle",
    "label": "Nur das Stichwort übertragen",
    "defaultValue": true
  },
  {
    "type":"select",
    "key": "format",
    "label": "Format",
    "description": "Datenformat in dem die Daten übertragen werden sollen",
    "options": [
      {
        "label": "JSON",
        "value": "json"
      },
      {
        "label": "XML",
        "value": "xml"
      }
    ]
  }
]

...

Hier ein Beispielscript welches mit dem Formular aus dem letzten Abschnitt genutzt werden könnte.

Codeblock
languagejsbash
themeMidnightDJango
local fetch = require("fetch")

-- Limitierung des Payloads
if configuration.onlyTitle then
  local payload = event.payload.title
else
  local payload = event.payload
end

-- Datentyp setzen
if configuration.format == "json" then
  local json = require("json")
  local data = json.encode(event.payload)
  local contentType = "application/json" 
elseif configuration.format == "xml" then
else
  print("Ungültiges Datenformat, breche ab.")
  return -- bricht die Ausführung eines Skripts ab
end

-- Anfrage senden
print(`Sende folgendes {contentType} an {configuration.url}: {data}`)
local response = fetch.post(configuration.url, {
  data = data,
  contentType = contentType
})
print(`Aufruf von "{configuration.url}" endete mit Status-Code {response.status_code}`)

...