mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
feat: allow ApiRequest component to create proxy requests
This commit is contained in:
parent
93d2ef55b9
commit
ecbae418d4
@ -53,3 +53,11 @@ DELETE.args = {
|
||||
url: 'api/admin/projects/<project-id>/features/<feature-toggle-id>',
|
||||
title: 'Create a feature toggle with impression data enabled.',
|
||||
};
|
||||
|
||||
export const GETProxy = Template.bind({});
|
||||
GETProxy.args = {
|
||||
verb: 'get',
|
||||
url: 'proxy',
|
||||
title: 'Request toggles from the Unleash Proxy',
|
||||
endpointType: 'Proxy API',
|
||||
};
|
||||
|
@ -18,47 +18,67 @@ import CodeBlock from '@theme/CodeBlock';
|
||||
const indentation = 2;
|
||||
|
||||
type Props = {
|
||||
verb: string,
|
||||
payload?: any,
|
||||
url: string,
|
||||
title?: string
|
||||
}
|
||||
verb: string;
|
||||
payload?: any;
|
||||
url: string;
|
||||
title?: string;
|
||||
endpointType?: 'Proxy API' | 'Unleash server API';
|
||||
};
|
||||
|
||||
const Component: React.FC<Props> = ({ verb, payload, url, title }) => {
|
||||
const Component: React.FC<Props> = ({
|
||||
verb,
|
||||
payload,
|
||||
url,
|
||||
title,
|
||||
endpointType = 'Unleash server API',
|
||||
}) => {
|
||||
const verbUpper = verb?.toUpperCase() || '';
|
||||
const prettyPayload = JSON.stringify(payload, null, indentation);
|
||||
const [baseUrl, authToken] =
|
||||
endpointType === 'Unleash server API'
|
||||
? ['unleash-url', 'API-token']
|
||||
: ['proxy-url', 'proxy-client-key'];
|
||||
|
||||
const httpBlock = (payload ? `
|
||||
${verbUpper} <unleash-url>/${url}
|
||||
Authorization: <API-token>
|
||||
const httpBlock = (
|
||||
payload
|
||||
? `
|
||||
${verbUpper} <${baseUrl}>/${url}
|
||||
Authorization: <${authToken}>
|
||||
content-type: application/json
|
||||
|
||||
${prettyPayload}` :`
|
||||
${verbUpper} <unleash-url>/${url}
|
||||
Authorization: <API-token>
|
||||
content-type: application/json`).trim()
|
||||
${prettyPayload}`
|
||||
: `
|
||||
${verbUpper} <${baseUrl}>/${url}
|
||||
Authorization: <${authToken}>
|
||||
content-type: application/json`
|
||||
).trim();
|
||||
|
||||
const curlBlock = (payload ? `
|
||||
const curlBlock = (
|
||||
payload
|
||||
? `
|
||||
curl -H "Content-Type: application/json" \\
|
||||
-H "Authorization: <API-token>" \\
|
||||
-H "Authorization: <${authToken}>" \\
|
||||
-X ${verbUpper} \\
|
||||
-d '${prettyPayload}' \\
|
||||
<unleash-url>/${url}` : `
|
||||
<${baseUrl}>/${url}`
|
||||
: `
|
||||
curl -H "Content-Type: application/json" \\
|
||||
-H "Authorization: <API-token>" \\
|
||||
-H "Authorization: <${authToken}>" \\
|
||||
-X ${verbUpper} \\
|
||||
<unleash-url>/${url}` ).trim()
|
||||
<${baseUrl}>/${url}`
|
||||
).trim();
|
||||
|
||||
const httpieBlock = (payload ?
|
||||
`echo '${prettyPayload}' \\
|
||||
const httpieBlock = (
|
||||
payload
|
||||
? `echo '${prettyPayload}' \\
|
||||
| http ${verbUpper} \\
|
||||
<unleash-url>/${url} \\
|
||||
Authorization:<API-token>`
|
||||
: `
|
||||
<${baseUrl}>/${url} \\
|
||||
Authorization:<${authToken}>`
|
||||
: `
|
||||
http ${verbUpper} \\
|
||||
<unleash-url>/${url} \\
|
||||
Authorization:<API-token>`.trim()
|
||||
).trim()
|
||||
<${baseUrl}>/${url} \\
|
||||
Authorization:<${authToken}>`.trim()
|
||||
).trim();
|
||||
|
||||
return (
|
||||
<Tabs groupId="api-request">
|
||||
@ -69,7 +89,7 @@ http ${verbUpper} \\
|
||||
</TabItem>
|
||||
<TabItem value="curl" label="cURL">
|
||||
<CodeBlock language="bash" title={title}>
|
||||
{curlBlock}
|
||||
{curlBlock}
|
||||
</CodeBlock>
|
||||
</TabItem>
|
||||
<TabItem value="httpie" label="HTTPie">
|
||||
|
Loading…
Reference in New Issue
Block a user