If you are not using React you may want to use the @asyncapi/web-component
component as a plain web component in any other web framework of your choice or as an element of a static HTML webpage. This is achieved by making use of web-react-components.
Run this command to install the component in your project:
npm install --save @asyncapi/web-component
Check out this simple sandbox application that uses the Web Component in Angular project:
Check how to use the Web Component in:
<!-- Remove 'webcomponentsjs' if no support for older browsers is required -->
<script src="https://unpkg.com/@webcomponents/[email protected]/webcomponents-bundle.js"></script>
<script src="https://unpkg.com/@asyncapi/[email protected]/lib/asyncapi-web-component.js" defer></script>
<asyncapi-component
schemaUrl="https://raw.githubusercontent.com/asyncapi/asyncapi/master/examples/2.0.0/streetlights.yml"
config='{"show": {"info": false}}'
schemaFetchOptions='{"method":"GET","mode":"cors"}' <!-- Remove if it is only a plain browser request -->
cssImportPath="https://unpkg.com/@asyncapi/[email protected]/styles/default.min.css">
</asyncapi-component>
NOTE: webcomponentsjs is a series of polyfills to make code runnable in old browsers. It is optional if you do not intend to support any.
NOTE: If a Web Component is called with no properties at all, the error will be shown on the page.
NOTE: If there are several Web Components on one page, each one will be rendered using its own properties.
When invoked as an independent entity, Web Component takes the following props (as it is still a React component):
schema
is aschema
property from the React component,NOTE: Since version 0.19.0 specifying a
schema
object can be omitted.schema.url
andschema.requestOptions
can be replaced withschemaUrl
andschemaFetchOptions
properties accordingly.config
is an optionalconfig
property from the React component in the stringified JSON format,schemaUrl
property is astring
, specific to Web Component, containing a URL to fetch an AsyncAPI Schema from. It is a wrapper forschema.url
property inschema
object under the hood,NOTE: If
schemaUrl
property is specified, theschema.url
property of the React component will be ignored.schemaFetchOptions
property is an optionalobject
of RequestInit type in JSON format, specific to Web Component, containing additional fetching options. It is a wrapper forschema.requestOptions
property inschema
object, which are both needed only in case process of fetching from a URL is any different from a usual browser request,NOTE: If
schemaFetchOptions
property is specified,schema.requestOptions
property of the React component will be ignored. IfschemaUrl
property is NOT specified,schemaFetchOptions
will be ignored itself andschema.url
/schema.requestOptions
properties of the React component must be used in this case.cssImportPath
property is the path to styles. Default version fromunpkg.com
contains guaranteed minimum styling for the Web Component,