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

> A request logic for Advanced REST Client excluding HTTP transport.

Latest version **3.0.3** (published 2020-01-08) · Apache-2.0 license · 0 weekly downloads

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

## Install

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

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.3 |
| Published | 2020-01-08 |
| First published | 2019-04-06 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 46.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jarrodek |
| Keywords | api-components, advanced-rest-client, request-processor, request-logic |

## Links

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

## Dependencies (4)

- [lit-element](https://npm.io/package/lit-element.md) ^2.2.1
- [@advanced-rest-client/events-target-mixin](https://npm.io/package/@advanced-rest-client/events-target-mixin.md) ^3.0.0
- [@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

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.0.3 (latest) — 2020-01-08
- 3.0.2 — 2019-12-31
- 3.0.1 — 2019-12-23
- 3.0.0 — 2019-08-07
- 3.0.0-preview.1 — 2019-04-06

## README

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

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

# 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](https://elements.advancedrestclient.com/)

## 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](https://github.com/TomFrost/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:

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

Setting path to Jexl:

```html
<arc-request-logic jexlpath="ArcVariables.JexlDev"></arc-request-logic>
```
This expects the Jexl library to be under `window.ArcVariables.JexlDev` variable.


### development

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

### Running the tests

```sh
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.

```javascript
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.

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