directus-extension-request-url-with-more-settings
Version:
Send HTTP requests with advanced settings: redirect behavior, and optional raw body output
2 lines (1 loc) • 2.38 kB
JavaScript
import{defineOperationApp as e}from"@directus/extensions-sdk";var t=e({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:e="GET",url:t,followRedirects:a=!0,rawBody:l=!1,uploadFromUrl:o=!1})=>[{label:"Method",text:e||"GET"},{label:"URL",text:t||""},{label:"Redirects",text:a?"follow":"manual"},{label:"Raw body",text:l?"yes":"no"},{label:"Upload from URL",text:o?"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:!0},{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:"uploadFromUrl",name:"Upload file from URL",type:"boolean",meta:{width:"half",interface:"boolean",default_value:!1,note:"Fetch a file from a given URL and upload it as multipart/form-data."}},{field:"fileUrl",name:"File URL",type:"string",meta:{width:"full",interface:"input",placeholder:"https://example.com/file.jpg",note:'URL of the file to fetch and upload (only used if "Upload from URL" is enabled).'}},{field:"followRedirects",name:"Follow redirects",type:"boolean",meta:{width:"half",interface:"boolean",default_value:!0}},{field:"rawBody",name:"Return raw body (base64)",type:"boolean",meta:{width:"half",interface:"boolean",default_value:!1,note:"Adds `rawBody` (base64) to the result."}}]});export{t as default};