API Components

Found an error? Have a suggestion?Edit this page on GitHub

Overview

This page describes the reusable components available in the AsyncAPI Generator.

CloseConnection

Renders a WebSocket close connection method with optional pre- and post-execution logic.

Example

1import { CloseConnection } from '@asyncapi/generator-components';
2
3const language = 'java';
4const methodName = 'terminateConnection';
5const methodParams = ['String reason'];
6const preExecutionCode = '// About to terminate connection';
7const postExecutionCode = '// Connection terminated';
8const indent = 2;
9
10function renderCloseConnection() {
11  return (
12    <CloseConnection
13      language={language}
14      methodName={methodName}
15      methodParams={methodParams}
16      preExecutionCode={preExecutionCode}
17      postExecutionCode={postExecutionCode}
18      indent={indent}
19    />
20  );
21}
22
23renderCloseConnection();

Connect

Renders a WebSocket connection method for the specified programming language.

Example

1import { Connect } from '@asyncapi/generator-components';
2
3const language = 'python';
4const title = 'HoppscotchEchoWebSocketClient';
5
6function renderConnect() {
7  return (
8    <Connect
9      language={language}
10      title={title}
11    />
12  );
13}
14
15renderConnect();

CoreMethods

Renders a list of core WebSocket client methods for a given target language.

Example

1import { CoreMethods } from '@asyncapi/generator-components';
2
3const language = 'javascript';
4
5function renderCoreMethods() {
6  return (
7    <CoreMethods language={language} />
8  );
9}
10
11renderCoreMethods();

DependencyProvider

Renders the top-of-file dependency statements for the selected programming language.

Example

1import { DependencyProvider } from '@asyncapi/generator-components';
2
3const language = 'java';
4const framework = 'quarkus';
5const role = 'client';
6const additionalDependencies = [
7  'import java.util.concurrent.CompletableFuture;',
8  'import java.time.Duration;',
9];
10
11function renderDependencyProvider() {
12  return (
13    <DependencyProvider
14      language={language}
15      framework={framework}
16      role={role}
17      additionalDependencies={additionalDependencies}
18    />
19  );
20}
21
22renderDependencyProvider();

Installation

Renders the installation command for a given language.

Example

1import { Installation } from '@asyncapi/generator-components';
2
3const language = 'javascript';
4
5function renderInstallation() {
6  return (
7    <Installation language={language} />
8  );
9}
10
11renderInstallation();

OnClose

Renders a WebSocket onClose event handler for the specified programming language.

Example

1import { OnClose } from '@asyncapi/generator-components';
2
3const language = 'java';
4const framework = 'quarkus';
5const title = 'HoppscotchEchoWebSocketClient';
6
7function renderOnClose() {
8  return (
9    <OnClose
10      language={language}
11      framework={framework}
12      title={title}
13    />
14  );
15}
16
17renderOnClose();

OnError

Renders a WebSocket onError event handler for the specified programming language.

Example

1import { OnError } from '@asyncapi/generator-components';
2
3const language = 'javascript';
4
5function renderOnError() {
6  return (
7    <OnError language={language} />
8  );
9}
10
11renderOnError();

OnMessage

Renders a WebSocket onMessage event handler for the specified programming language.

Example

1import { OnMessage } from '@asyncapi/generator-components';
2
3const language = 'javascript';
4
5function renderOnMessage() {
6  return (
7    <OnMessage language={language} />
8  );
9}
10
11renderOnMessage();

OnOpen

Renders a WebSocket onOpen event handler for the specified programming language.

Example

1import { OnOpen } from '@asyncapi/generator-components';
2
3const language = 'java';
4const framework = 'quarkus';
5const title = 'HoppscotchEchoWebSocketClient';
6
7function renderOnOpen() {
8  return (
9    <OnOpen
10      language={language}
11      framework={framework}
12      title={title}
13    />
14  );
15}
16
17renderOnOpen();

Usage

Renders a usage example snippet for a generated WebSocket client in a given language.

Example

1import { Usage } from '@asyncapi/generator-components';
2
3const clientName = 'MyClient';
4const clientFileName = 'myClient.js';
5const language = 'javascript';
6
7function renderUsage() {
8  return (
9    <Usage
10      clientName={clientName}
11      clientFileName={clientFileName}
12      language={language}
13    />
14  );
15}
16renderUsage();
17
Was this helpful?
Help us improve the docs by adding your contribution.
OR
Github:AsyncAPICreate Issue on GitHub