Skip to content

Commit 678fa6b

Browse files
committed
chore: adding electron request module
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 98536ba commit 678fa6b

File tree

99 files changed

+16108
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+16108
-53
lines changed

.github/workflows/deployment.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Node CI
2+
3+
env:
4+
FORCE_COLOR: 1
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
- main
11+
- develop
12+
pull_request:
13+
branches:
14+
- master
15+
- main
16+
17+
jobs:
18+
test_linux:
19+
name: Ubuntu
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions/setup-node@v1
24+
with:
25+
node-version: 14
26+
- uses: actions/cache@v1
27+
with:
28+
path: ~/.npm
29+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
30+
restore-keys: |
31+
${{ runner.os }}-node-
32+
- name: install required packages
33+
run: |
34+
sudo apt-get install libwoff1 libopus0 libwebp6 libwebpdemux2 libenchant1c2a libgudev-1.0-0 libsecret-1-0 libhyphen0 libgdk-pixbuf2.0-0
35+
sudo apt-get install xvfb
36+
export DISPLAY=:99.0
37+
Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &
38+
- name: Install dependencies
39+
run: npm ci
40+
- name: Run tests
41+
run: xvfb-run --auto-servernum npm run test
42+
test_win:
43+
name: "Windows"
44+
runs-on: windows-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- uses: actions/setup-node@v1
48+
with:
49+
node-version: 14
50+
- uses: actions/cache@v1
51+
with:
52+
path: ~/.npm
53+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
54+
restore-keys: |
55+
${{ runner.os }}-node-
56+
- name: Install dependencies
57+
run: npm ci
58+
- name: Run tests
59+
run: npm test
60+
tag:
61+
name: "Publishing release"
62+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
63+
needs:
64+
- test_linux
65+
- test_win
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Checkout code
69+
uses: actions/checkout@v2
70+
with:
71+
fetch-depth: 0
72+
- uses: actions/setup-node@v2
73+
with:
74+
node-version: '14.x'
75+
registry-url: 'https://registry.npmjs.org'
76+
- uses: actions/cache@v1
77+
with:
78+
path: ~/.npm
79+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
80+
restore-keys: |
81+
${{ runner.os }}-node-
82+
- run: npm install
83+
- name: Read version from package.json
84+
uses: culshaw/read-package-node-version-actions@v1
85+
id: package-node-version
86+
- name: Changelog
87+
uses: scottbrenner/generate-changelog-action@master
88+
id: Changelog
89+
- name: Github Release
90+
id: create_release
91+
uses: actions/create-release@latest
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
with:
95+
tag_name: v${{ steps.package-node-version.outputs.version }}
96+
release_name: v${{ steps.package-node-version.outputs.version }}
97+
body: |
98+
${{ steps.Changelog.outputs.changelog }}
99+
draft: false
100+
prerelease: false
101+
- run: npm publish --access public
102+
env:
103+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

docs/http.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Electron request
2+
3+
The HTTP engine for the Advanced REST Client application.
4+
5+
It works in the Electron's renderer process and allows to make a HTTP request resulting with detailed response.
6+
7+
The detailed response contains information about redirects and timings similar to the ones presented by Chrome Dev Tools.
8+
9+
## Usage
10+
11+
The library contain two HTTP clients:
12+
13+
- `SocketRequest` - ARC's original and own HTTP client. Operates directly on the socket.
14+
- `ElectronRequest` - A request engine using higher level Node's APIs
15+
16+
Both classes use the same configuration and produce the same output.
17+
18+
### Socket request
19+
20+
Originally `SocketRequest` was develop for ARC Chrome Application as Chrome apps don't have access to low level request APIs and therefore the application was unable to produce detailed information about the request.
21+
22+
```javascript
23+
import { SocketRequest } from '@advanced-rest-client/electron-request';
24+
25+
const opts = {
26+
timeout: 30000,
27+
hosts: [{from: 'domain.com', to: 'other.com'}],
28+
followRedirects: true
29+
};
30+
const id = 'some-id';
31+
const request = {
32+
url: 'http://api.domain.com',
33+
method: 'GET',
34+
headers: 'x-test: true'
35+
};
36+
37+
const connection = new SocketRequest(request, id, opts);
38+
request.on('load', (id, response, transport) => {});
39+
request.on('error', (error, id, transport, response) => {});
40+
try {
41+
await connection.send();
42+
console.log('Request message sent.');
43+
} catch (cause) {
44+
// usually it means that the server is down or configuration is invalid (URL).
45+
console.error('Connection error', cause);
46+
}
47+
```
48+
49+
The `transport` is defined in `@advanced-rest-client/arc-types` as `TransportRequest` interface and describes the final message that has been sent to the endpoint. This includes all transformations applied to the request like added headers.
50+
51+
### Native request
52+
53+
Electron application can access Node's APIs and therefore `SocketRequest` can be eventually replaced to reduce amount of code to maintain.
54+
55+
```javascript
56+
import { ElectronRequest } from '@advanced-rest-client/electron-request';
57+
58+
const opts = {
59+
timeout: 30000,
60+
hosts: [{from: 'domain.com', to: 'other.com'}],
61+
followRedirects: true
62+
};
63+
const id = 'some-id';
64+
const request = {
65+
url: 'http://api.domain.com',
66+
method: 'GET',
67+
headers: 'x-test: true'
68+
};
69+
70+
const connection = new ElectronRequest(request, id, opts);
71+
request.on('load', (id, response, transport) => {});
72+
request.on('error', (error, id, transport, response) => {});
73+
try {
74+
await connection.send();
75+
console.log('Request message sent.');
76+
} catch (cause) {
77+
// usually it means that the server is down or configuration is invalid (URL).
78+
console.error('Connection error', cause);
79+
}
80+
```

0 commit comments

Comments
 (0)