-
-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add API request component: display in http and httpie easy!
The ApiRequest component is created to make it easier to show code samples for API requests. It shows them in raw HTTP form and with HTTPie for now.
- Loading branch information
1 parent
323b9e4
commit 752a1df
Showing
4 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
This component displays API requests in multiple different formats | ||
using the tabs component. It syncs across the page. | ||
Please note: it doees NOT cover all kinds of API requests just yet. | ||
If the type you're looking for isn't included, you may need to do | ||
some extra development before it can be used. In the future, it may | ||
be necessary to separate into multiple components based on request | ||
types, for instance. | ||
**/ | ||
|
||
import React from 'react'; | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
|
||
const indentation = 2; | ||
|
||
const Component = ({ verb, payload, url, title }) => { | ||
const verbUpper = verb?.toUpperCase() || "" | ||
const prettyPayload = JSON.stringify(payload, null, indentation) | ||
|
||
return ( | ||
<Tabs groupId="api-request"> | ||
<TabItem value="http" label="HTTP"> | ||
<CodeBlock language="http" title={title}> | ||
{`${verbUpper} <unleash-url>/${url} | ||
Authorization: <API-token> | ||
content-type: application/json | ||
${prettyPayload} | ||
`} | ||
</CodeBlock> | ||
</TabItem> | ||
<TabItem value="httpie" label="HTTPie"> | ||
<CodeBlock language="bash" title={title}> | ||
{`echo '${prettyPayload}' \\ | ||
| http ${verbUpper} \\ | ||
<unleash-url>/${url} \\ | ||
Authorization:<API-token>`} | ||
</CodeBlock> | ||
</TabItem> | ||
</Tabs> | ||
); | ||
}; | ||
|
||
export default Component; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.