1
0
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:
Thomas Heartman 2022-04-13 15:15:08 +02:00
parent 93d2ef55b9
commit ecbae418d4
2 changed files with 55 additions and 27 deletions

View File

@ -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',
};

View File

@ -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">