This package has been deprecated

    Author message:

    This component is deprecated

    @advanced-rest-client/arc-request-logic
    TypeScript icon, indicating that this package has built-in type declarations

    3.0.3 • Public • Published

    Published on NPM

    Build Status

    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.

    API components

    This components is a part of API components ecosystem

    Usage

    Installation

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

    Jexl dependency

    This library uses @advanced-rest-client/arc-request-logic which depend on Jexl and this library is not included by default in the element. You need to add this dependency manually.

    You must install Jexl on your project, and build it for browser. See dev-lib/ folder for an example of such a build.

    Finally you have to either pass the pointer to Jexl library to jexl property or point to a relative in the window object.

    Setting Jexl reference:

    const eval = document.querySelector('arc-request-logic');
    eval.jexl = myJexlVariable;

    Setting path to Jexl:

    <arc-request-logic jexlpath="ArcVariables.JexlDev"></arc-request-logic>

    This expects the Jexl library to be under window.ArcVariables.JexlDev variable.

    development

    git clone https://github.com/advanced-rest-client/arc-request-logic
    cd arc-request-logic
    npm install

    Running the tests

    npm test

    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.

    Install

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

    DownloadsWeekly Downloads

    1

    Version

    3.0.3

    License

    Apache-2.0

    Unpacked Size

    48 kB

    Total Files

    7

    Last publish

    Collaborators

    • carowright
    • jarrodek
    • twoplustwoone
    • lbauret