Socket
Socket
Sign inDemoInstall

@advanced-rest-client/arc-request-logic

Package Overview
Dependencies
7
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @advanced-rest-client/arc-request-logic

A request logic for Advanced REST Client excluding HTTP transport.


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Published on NPM

Build Status

Published on webcomponents.org

arc-request-logic

A request logic for Advanced REST Client excluding HTTP transport.

This component is responsible for handing api-request event, handing variables processing, request actions, before-request event, dispatching URL history store event, communicating with transport library, and finally dispatching api-response event. If the transport library it the hearth of the application then this component is it's brain.

This library uses @advanced-rest-client/variables-evaluator which depend on Jexl (version 2.x) and this library is not included by default in the element. You need to add this dependency manually.

Example:

<arc-request-logic></arc-request-logic>

API components

This components is a part of API components ecosystem

Usage

Installation

npm install --save @advanced-rest-client/arc-request-logic

In an html file

<html>
  <head>
    <script type="module">
      import './node_modules/@advanced-rest-client/arc-request-logic/arc-request-logic.js';
    </script>
  </head>
  <body>
    <arc-request-logic></arc-request-logic>
  </body>
</html>

In a Polymer 3 element

import {PolymerElement, html} from './node_modules/@polymer/polymer/polymer-element.js';
import './node_modules/@advanced-rest-client/arc-request-logic/arc-request-logic.js';

class SampleElement extends PolymerElement {
  static get template() {
    return html`
    <arc-request-logic></arc-request-logic>
    `;
  }
}
customElements.define('sample-element', SampleElement);

Installation

git clone https://github.com/advanced-rest-client/arc-request-logic
cd api-url-editor
npm install
npm install -g polymer-cli

Running the demo locally

polymer serve --npm
open http://127.0.0.1:<port>/demo/

Running the tests

polymer test --npm

Middleware

Handle before-request custom event to alter request properties before send. When the handler is synchronous then there's no need for additional steps.

If the handler is asynchronous then add a Promise to the promises array on detail object and resolve it when ready. It is possible to set timeout property on the promise to extend default timeout for before-request event processing which is set to 2000ms.

document.body.addEventListener('before-request', (e) => {
  cont p = new Promise((resolve) => {
    sync processUrl(e.detail); // set new URL on the detail object as objects are passed by reference
    resolve();
  });
  p.timeout = 3500;
  e.detail.promises.push(p);
});

document.body.dispatchEvent(new CustomEvent('api-request', {
  bubbles: true,
  cancelable: true,
  detail: request
});

Mind that other handlers may interact with the same properties. Even though there's no race conditions per so in JavaScript you may get different values between processing different parts of request if the event loop is releases.

Keywords

FAQs

Last updated on 06 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc