amf-components
A set of web components based on LitElement that creates the visualization layer on top of the AMF's graph model.
This project replaces all api-*
components from this organization and consolidates the code base under a single repository.
Usage
Installation
npm install --save @api-components/amf-components
Example
<html>
<head>
<script type="module">
import '@api-components/amf-components/define/api-documentation.js';
import '@api-components/amf-components/define/api-request.js';
import '@api-components/amf-components/define/api-navigation.js';
import '@api-components/amf-components/define/xhr-simple-request.js';
import '@advanced-rest-client/app/define/oidc-authorization.js';
import '@advanced-rest-client/app/define/oauth2-authorization.js';
</script>
</head>
<body>
<!-- A helper library that works with <api-request> to perform an HTTP request in the browser. -->
<xhr-simple-request></xhr-simple-request>
<!-- Authorization libraries to perform OAuth and OIDC authorization. -->
<oauth2-authorization></oauth2-authorization>
<oidc-authorization></oidc-authorization>
<nav>
<!-- The navigation element. Starts with the "summary" page selection. -->
<api-navigation summary domainId="summary" domainType="summary"></api-navigation>
</nav>
<main>
<!-- The main documentation element. Starts with the "summary" page selection. -->
<api-documentation handleNavigationEvents domainId="summary" domainType="summary"></api-documentation>
</main>
<aside>
<!-- The HTTP request editor. Renders forms for user input to make an HTTP request -->
<api-request handleNavigationEvents></api-request>
</aside>
<script type="module">
import { DomEventsAmfStore } from '@api-components/amf-components';
(async () => {
const apiStore = new DomEventsAmfStore();
apiStore.listen();
apiStore.amf = await getAmfModelSomehow();
})();
</script>
</body>
</html>
API store
The components, unlike previously, do not rely on the graph model generated by the AMF parser. Instead they use a custom JavaScript objects generated by the src/helpers/AmfSerializer.js class. These models are provided to the components by the src/store/AmfStore.js or the src/store/DomEventsAmfStore.js. This was developers implementing the components have the most flexibility of providing the console with the graph model that source may be in a different location (like HTTP queries).
See docs/architecture.md for more details.
Monaco editor
The request editor uses the Monaco editor (by Microsoft) to render the body editor.
The library has to be loaded to the document before the request editor is rendered. Use the @advanced-rest-client/monaco-support
module and MonacoLoader
class to load the editor with defaults.
import { MonacoLoader } from '@advanced-rest-client/monaco-support';
const base = new URL(`../node_modules/monaco-editor/`, window.location.href).toString();
MonacoLoader.createEnvironment(base);
await MonacoLoader.loadMonaco(base);
await MonacoLoader.monacoReady();
Development
git clone https://github.com/api-components/amf-components
cd amf-components
npm install
Running the demo locally
npm start
Running the tests
npm test