Plugin for @asyncapi/react-component that adds a Try it out action for operation blocks.
npm i asyncapi-try-it-pluginimport AsyncApiComponent from '@asyncapi/react-component';
import { createTryItOutPlugin } from 'asyncapi-try-it-plugin';
const tryItOutPlugin = createTryItOutPlugin({
endpointBase: 'asyncapi/try',
});
<AsyncApiComponent schema={schema} plugins={[tryItOutPlugin]} />;createTryItOutPlugin({
endpointBase?: string;
showEndpointInput?: boolean;
showPayloadSchema?: boolean;
showRealBrokerToggle?: boolean;
buttonLabel?: string;
additionalFields?: Array<{
key: string;
type: 'string' | 'number' | 'integer' | 'boolean';
label?: string;
defaultValue?: unknown;
}>;
resolveEndpoint?: (ctx: {
operationId: string;
operationAction: string;
channelName: string;
type: string;
endpointBase: string;
}) => string;
});Defaults:
endpointBase: 'asyncapi/try'showEndpointInput: falseshowPayloadSchema: falseshowRealBrokerToggle: truebuttonLabel: 'Try it out'additionalFields: []
Default endpoint:
/${endpointBase}
- Two input modes are supported:
FormandRaw JSON. operation_idandoperation_typeare always added to outgoing payload automatically.- In
Formmode these metadata fields are hidden from the form. - In
Raw JSONmode these metadata fields are prefilled and kept in sync. - For array payload schemas, the
Formmode renders an add/remove item editor.
POST body:
{
"channelName": "string",
"message": {
"operation_id": "string",
"operation_type": "string",
"message": "<payload>"
},
"options": {
"sendToRealBroker": false,
"timestamp": "ISO string"
}
}message.message matches the AsyncAPI payload schema type:
| Schema type | message.message value |
|---|---|
object |
{ "field": "value", ... } |
string |
"hello" |
integer / number |
42 |
boolean |
true |
array |
["a", "b"] |
null |
null |