From 65da8a845aff2845774dffa1b4e87f4562a56e77 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Wed, 27 Apr 2022 10:55:33 +0200 Subject: [PATCH] feat: update ApiRequest to accept POST w/o payloads --- website/src/components/ApiRequest/ApiRequest.stories.jsx | 7 +++++++ website/src/components/ApiRequest/index.tsx | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/website/src/components/ApiRequest/ApiRequest.stories.jsx b/website/src/components/ApiRequest/ApiRequest.stories.jsx index 4c177e42d7c..a50ce3a2a16 100644 --- a/website/src/components/ApiRequest/ApiRequest.stories.jsx +++ b/website/src/components/ApiRequest/ApiRequest.stories.jsx @@ -31,6 +31,13 @@ POST.args = { title: 'Create a feature toggle with impression data enabled. (example)', }; +export const POSTWithoutPayload = Template.bind({}); +POSTWithoutPayload.args = { + verb: 'post', + url: 'api/admin/projects//features//environments//on', + title: 'Disable a toggle in an env.', +}; + export const PUT = Template.bind({}); PUT.args = { verb: 'put', diff --git a/website/src/components/ApiRequest/index.tsx b/website/src/components/ApiRequest/index.tsx index 4727dd91fce..84fa595a32d 100644 --- a/website/src/components/ApiRequest/index.tsx +++ b/website/src/components/ApiRequest/index.tsx @@ -68,6 +68,9 @@ curl -H "Content-Type: application/json" \\ <${baseUrl}>/${url}` ).trim(); + const httpieBlockFormatSpecifier = + verbUpper === 'POST' && !prettyPayload ? '--json' : ''; + const httpieBlock = ( payload ? `echo '${prettyPayload}' \\ @@ -77,7 +80,8 @@ curl -H "Content-Type: application/json" \\ : ` http ${verbUpper} \\ <${baseUrl}>/${url} \\ - Authorization:<${authToken}>`.trim() + Authorization:<${authToken}> \\ + ${httpieBlockFormatSpecifier}`.trim() ).trim(); return (