UNPKG

directus-extension-request-url-with-more-settings

Version:

Send HTTP requests with advanced settings: redirect behavior, and optional raw body output

111 lines (108 loc) 2.99 kB
import { defineOperationApp } from '@directus/extensions-sdk'; var app = defineOperationApp({ id: "request-url-with-more-settings", name: "HTTP Request (Advanced)", icon: "send", description: "Send an HTTP request with method, headers, body, and redirect control. Optionally return raw body (base64).", overview: ({ method = "GET", url, followRedirects = true, rawBody = false }) => [ { label: "Method", text: method || "GET" }, { label: "URL", text: url || "" }, { label: "Redirects", text: followRedirects ? "follow" : "manual" }, { label: "Raw body", text: rawBody ? "yes" : "no" } ], options: [ { field: "method", name: "Method", type: "string", meta: { width: "half", interface: "select-dropdown", options: { choices: [ { text: "GET", value: "GET" }, { text: "POST", value: "POST" }, { text: "PUT", value: "PUT" }, { text: "DELETE", value: "DELETE" }, { text: "PATCH", value: "PATCH" }, { text: "HEAD", value: "HEAD" }, { text: "OPTIONS", value: "OPTIONS" } ] }, default_value: "GET" } }, { field: "url", name: "URL", type: "string", meta: { width: "full", interface: "input", placeholder: "https://example.com/api", note: "Include the scheme (http/https)." }, required: true }, { field: "headers", name: "Headers", type: "json", meta: { width: "full", interface: "list", options: { addLabel: "Add header", fields: [ { field: "header", name: "Header", type: "string", meta: { interface: "input", width: "half", placeholder: "Content-Type" } }, { field: "value", name: "Value", type: "string", meta: { interface: "input", width: "half", placeholder: "application/json" } } ] }, default_value: [] } }, { field: "body", name: "Body", type: "json", meta: { width: "full", interface: "input-code", options: { language: "json", placeholder: '{ "foo": "bar" }' }, note: "If an object is provided, it will be JSON.stringified unless you set Content-Type yourself." } }, { field: "followRedirects", name: "Follow redirects", type: "boolean", meta: { width: "half", interface: "boolean", default_value: true } }, { field: "rawBody", name: "Return raw body (base64)", type: "boolean", meta: { width: "half", interface: "boolean", default_value: false, note: "Adds `rawBody` (base64) to the result." } } ] }); export { app as default };