弧定义
Adavanced REST客户端和API Console中使用的请求/响应头和状态代码定义数据库.
这个 <arc-definitions> 元素会监听查询事件.
其他元素可以发送 query-headers 财务报告和审定财务报表 query-status-codes 由此元素处理的事件。 事件被禁止传播.
控件事件接收新属性 detail 带有查询结果的对象.
使用量
发送查询事件
查询信头数据
每个标题定义项具有以下属性:
key- 字符串,标题的名称desc- 字符串,信头的文档example- 字符串,标题的示例值autocomplete- 字符串组合,自动完成函数的可能/示例值列表。 此属性不适用于响应头 .
{
"key": "Accept-Charset",
"desc": "Character sets that are acceptable",
"example": "Accept-Charset: utf-8",
"autocomplete": ["utf-8"]
}
要查询信头数据发送 query-headers 事件:
const e = new CustomEvent('query-headers', {
detail: {
type: 'request', // or "response"
query: 'Acce'
},
bubbles: true,
cancelable: true
});
document.body.dispatchEvent(e);
console.log(event.defaultPrevented); // true
const headers = event.detail.headers; // Array[...]
或使用必需的 API :
const data = document.querySelector('arc-definitions').queryHeaders('A', 'response');
console.log(data); // list of headers with "A" in the name
查询状态代码数据
状态代码定义项有以下属性:
key- 号码,代码值desc- 字符串,状态代码的文档label- 字符串、 与代码相关的状态标签
{
"key": 101,
"label": "Switching Protocols",
"desc":"This means the requester has asked the server to switch protocols and the server is acknowledging that it will do so"
}
查询状态代码定义发送 query-status-codes 事件:
const e = new CustomEvent('query-status-codes', {
detail: {
code: 200
},
bubbles: true,
cancelable: true
});
document.body.dispatchEvent(e);
console.log(event.defaultPrevented); // true
const statusCode = event.detail.statusCode; // {...}
或使用必需的 API :
const status = document.querySelector('arc-definitions').getStatusCode(201);
console.log(status); // Status code definition for 201
安装
npm install --save @advanced-rest-client/arc-definitions
在 html 文件内
<html>
<head>
<script type="module">
import '@advanced-rest-client/arc-definitions/arc-definitions.js';
</script>
</head>
<body>
<arc-definitions></arc-definitions>
</body>
</html>
在一个LitElement中
import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/arc-definitions/arc-definitions.js';
class SampleElement extends LitElement {
render() {
return html`
<arc-definitions></arc-definitions>
`;
}
}
customElements.define('sample-element', SampleElement);
在多聚体3元素中
import {PolymerElement, html} from '@polymer/polymer';
import '@advanced-rest-client/arc-definitions/arc-definitions.js';
class SampleElement extends PolymerElement {
static get template() {
return html`
<arc-definitions></arc-definitions>
`;
}
_authChanged(e) {
console.log(e.detail);
}
}
customElements.define('sample-element', SampleElement);
发展
git clone https://github.com/advanced-rest-client/arc-definitions
cd arc-definitions
npm install
本地运行演示
npm start
运行测试
npm test