# @advanced-rest-client/request-hooks-logic

> Package containing a logic for creating HTTP request / response hooks

Latest version **3.0.0** (published 2019-08-03) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @advanced-rest-client/request-hooks-logic
pnpm add @advanced-rest-client/request-hooks-logic
yarn add @advanced-rest-client/request-hooks-logic
bun add @advanced-rest-client/request-hooks-logic
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-08-03 |
| First published | 2018-02-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 238.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jarrodek |
| Keywords | api-console, builder, node |

## Links

- npm: https://www.npmjs.com/package/@advanced-rest-client/request-hooks-logic
- Repository: https://github.com/advanced-rest-client/request-hooks-logic
- Homepage: https://github.com/advanced-rest-client/request-hooks-logic#readme
- Issues: https://github.com/advanced-rest-client/request-hooks-logic/issues
- npm.io page: https://npm.io/package/@advanced-rest-client/request-hooks-logic

## Dependencies (3)

- [lit-element](https://npm.io/package/lit-element.md) ^2.2.1
- [@advanced-rest-client/variables-evaluator](https://npm.io/package/@advanced-rest-client/variables-evaluator.md) ^3.0.0
- [@advanced-rest-client/headers-parser-mixin](https://npm.io/package/@advanced-rest-client/headers-parser-mixin.md) ^3.0.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2019-08-03
- 3.0.0-preview.1 — 2019-04-04
- 0.1.3 — 2018-02-16
- 0.1.2 — 2018-02-09
- 0.1.1 — 2018-02-09
- 0.1.0 — 2018-02-08

## README

[![Published on NPM](https://img.shields.io/npm/v/@advanced-rest-client/request-hooks-logic.svg)](https://www.npmjs.com/package/@advanced-rest-client/request-hooks-logic)

[![Build Status](https://travis-ci.org/advanced-rest-client/request-hooks-logic.svg?branch=stage)](https://travis-ci.org/advanced-rest-client/request-hooks-logic)

[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/advanced-rest-client/request-hooks-logic)

# request-hooks-logic

Package containing a logic for creating HTTP request / response hooks for Advanced REST Client.

The documentation for request actions (including data model) can be found in [ARC electron wiki page](https://github.com/advanced-rest-client/arc-electron/wiki/Request-actions).

## Example:

```html
<request-hooks-logic></request-hooks-logic>
<script>
{
  const actions = [{
    source: 'response.value',
    action: 'assign-variable',
    destination: 'itemId',
    hasIterator: true,
    iterator: {
      source: 'json.*.id',
      operator: 'equal',
      condition: 'id2'
    },
    conditions: [{
      enabled: true,
      source: 'response.status',
      operator: 'equal',
      condition: '200'
    }]
  }];
  const request = {};
  const response = {
    url: '...',
    headers: 'content-type: application/json',
    payload: '{"json": [{"id": "id1", "value": "v1"}, {"id": "id2", "value": "v2"}]}'
  };

  const logic = document.querySelector('request-hooks-logic');
  logic.processActions(actions, request, response)
  .then(() => {
    // done, variables are set, if any
  });
}
</script>
```

When this action is executed it informs `variables-manager` to set in-memory variable called `itemId` and it's value to be set to `v2`. The logic runner iterates over the response in a path defined as `json.*.id`. When the right object is found by the iterator then the value is set from `source` property.

## API components

This components is a part of [API components ecosystem](https://elements.advancedrestclient.com/)

## Jexl dependency

Previous versions of this component included Jexl library. This version do not have
Jexl as a dependency but it is required to run the component.

You must install [Jexl](https://github.com/TomFrost/Jexl) on your project, and build it for browser.
See `dev-lib/` folder for an example of such build.

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

Setting Jexl pointer:

```javascript
const eval = document.querySelector('request-hooks-logic');
eval.jexl = myJexlVariable;
```

Setting path to Jexl:

```html
<request-hooks-logic jexlpath="ArcVariables.JexlDev"></request-hooks-logic>
```

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

## Usage

### Installation
```
npm install --save @advanced-rest-client/request-hooks-logic
```

### In a LitElement template

```javascript
import { LitElement, html } from 'lit-element';
import '@advanced-rest-client/request-hooks-logic/request-hooks-logic.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <request-hooks-logic jexl="${this.jexlRef}"></request-hooks-logic>
    `;
  }

  async processResponse(request, response) {
    const node = this.shadowRoot.querySelector('request-hooks-logic');
    const actions = await getActions();
    await logic.processActions(actions, request, response);
  }
}
customElements.define('sample-element', SampleElement);
```

### Development

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

### Running the tests

```sh
npm test
```

---
_Source: https://npm.io/package/@advanced-rest-client/request-hooks-logic · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
