api-url-editor

WebJar for api-url-editor

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

org.webjars.bowergithub.advanced-rest-client
ArtifactId

ArtifactId

api-url-editor
Last Version

Last Version

2.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

api-url-editor
WebJar for api-url-editor
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/advanced-rest-client/api-url-editor

Download api-url-editor

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/api-url-editor/ -->
<dependency>
    <groupId>org.webjars.bowergithub.advanced-rest-client</groupId>
    <artifactId>api-url-editor</artifactId>
    <version>2.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/api-url-editor/
implementation 'org.webjars.bowergithub.advanced-rest-client:api-url-editor:2.0.6'
// https://jarcasting.com/artifacts/org.webjars.bowergithub.advanced-rest-client/api-url-editor/
implementation ("org.webjars.bowergithub.advanced-rest-client:api-url-editor:2.0.6")
'org.webjars.bowergithub.advanced-rest-client:api-url-editor:jar:2.0.6'
<dependency org="org.webjars.bowergithub.advanced-rest-client" name="api-url-editor" rev="2.0.6">
  <artifact name="api-url-editor" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bowergithub.advanced-rest-client', module='api-url-editor', version='2.0.6')
)
libraryDependencies += "org.webjars.bowergithub.advanced-rest-client" % "api-url-editor" % "2.0.6"
[org.webjars.bowergithub.advanced-rest-client/api-url-editor "2.0.6"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.bowergithub.polymerelements : paper-input jar [2.2.0,3)
org.webjars.bowergithub.polymerelements : iron-validatable-behavior jar [2.1.0,3)
org.webjars.bowergithub.advanced-rest-client » events-target-behavior jar [2.0.1,3)
org.webjars.bowergithub.polymer : polymer jar [2.0.0,3)
org.webjars.bowergithub.polymerelements : iron-flex-layout jar [2.0.3,3)

Project Modules

There are no modules declared in this project.

Published on NPM

Build Status

api-url-editor

An AMF powered URL editor for the HTTP request editor.

It uses api-url-data-model to transform AMF model to the view model recognized by this element.

<api-url-editor
  required
  amf="..."
  baseuri="https://api.domain.com"
  endpointpath="/users/me"
  querymodel="..."
  pathmodel="..."></api-url-editor>

Deprecation notice

This element is moved to api-url repository and @api-components/api-url package. This element will be deprecated and archived once the migration finish.

Version compatibility

This version only works with AMF model version 2 (AMF parser >= 4.0.0). For compatibility with previous model version use 3.x.x version of the component.

Usage

Installation

npm install --save @api-components/api-url-editor

In an html file

<html>
  <head>
    <script type="module">
      import '@api-components/api-url-editor/api-url-editor.js';
    </script>
  </head>
  <body>
    <api-url-editor></api-url-editor>
    <script>
    {
      const editor = document.querySelector('api-url-editor');
      editor.amf = {...};
      editor.onvalue = (e) {
        console.log('URL value', e.target.value);
      };
    }
    </script>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@api-components/api-url-editor/api-url-editor.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <api-url-editor
      required
      ?disabled="${this.disabled}"
      ?outlined="${this.outlined}"
      ?legacy="${this.legacy}"
      ?noLabelFloat="${this.noLabelFloat}"
      .amf="${this.amf}"
      .baseUri="${this.apiBaseUri}"
      .endpointPath="${this.endpointPath}"
      .queryModel="${this.queryModel}"
      .pathModel="${this.pathModel}"
      @value-changed="${this._handleValue}"></api-url-editor>
    `;
  }

  _handleValue(e) {
    this.urlValue = e.target.value;
  }
}
customElements.define('sample-element', SampleElement);

Passing AMF data model

The component does not directly interact with AMF model. It uses a view model generated by api-url-data-model. This element parses API spec to produce basic information about currently selected endpoint like path variables model, query parameters model, and base URI.

Your UI has to provide a way to select an endpoint. You can use api-navigation element which renders API structure in a nav bar and dispatches selection event.

In an html file

<api-url-editor></api-url-editor>
<api-url-data-model></<api-url-data-model>

<script type="module">
import '@api-components/api-url-editor/api-url-editor.js';
import '@api-components/api-url-data-model/api-url-data-model.js';

{
  const api = await generateApiModel();
  const selectedEndpoint = 'amf://id#63'; // some ID from the AMF model for endpoint / operation

  const model = document.querySelector('api-url-data-model');
  model.amf = api; // This is required to compute ld+json keys!
  model.server = server; // a server for current selection
  model.selected = selectedEndpoint;

  const editor = document.querySelector('api-url-editor');
  model.amf = api;
  editor.baseUri = model.apiBaseUri;
  editor.endpointPath = model.endpointPath;
  editor.queryModel = model.queryModel;
  editor.pathModel = model.pathModel;
}
</script>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@api-components/api-url-editor/api-url-editor.js';

class SampleElement extends LitElement {
  static get properties() {
    return {
      amfModel: { type: Object },
      selectedShape: { type: String },
      apiBaseUri: { type: String },
      endpointPath: { type: String },
      queryModel: { type: Array },
      pathModel: { type: Array },
      ...
    }
  }

  render() {
    return html`
    <api-url-data-model
      @apibaseuri-changed="${this._baseUrlChangeHandler}"
      @endpointpath-changed="${this._endpointPathChangeHandler}"
      @pathmodel-changed="${this._pathModelChangeHandler}"
      @querymodel-changed="${this._queryModelChangeHandler}"
      .server="${server}"
      .selected="${this.selectedShape}"
      .amf="${this.amfModel}"
    ></api-url-data-model>
    <api-url-editor
      required
      ?disabled="${this.disabled}"
      ?outlined="${this.outlined}"
      ?compatibility="${this.compatibility}"
      ?noLabelFloat="${this.noLabelFloat}"
      .amf="${this.amfModel}"
      .baseUri="${this.apiBaseUri}"
      .endpointPath="${this.endpointPath}"
      .queryModel="${this.queryModel}"
      .pathModel="${this.pathModel}"
      @value-changed="${this._handleValue}"></api-url-editor>
    `;
  }

  _handleValue(e) {
    this.urlValue = e.target.value;
  }

  _baseUrlChangeHandler(e) {
    this.apiBaseUri = e.detail.value;
  }

  _endpointPathChangeHandler(e) {
    this.endpointPath = e.detail.value;
  }

  _queryModelChangeHandler(e) {
    this.queryModel = e.detail.value;
  }

  _pathModelChangeHandler(e) {
    this.pathModel = e.detail.value;
  }
}
customElements.define('sample-element', SampleElement);

Development

git clone https://github.com/advanced-rest-client/api-url-editor
cd api-url-editor
npm install

Running the demo locally

npm start

Running the tests

npm test

API components

This components is a part of API components ecosystem

org.webjars.bowergithub.advanced-rest-client

ARC

A set of repositories related to the Advanced REST Client and API console (by Mulesoft)

Versions

Version
2.0.6