🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

supra-http

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

supra-http - npm Package Compare versions

Comparing version

to
1.0.8

4

dist/client.d.ts

@@ -1,12 +0,8 @@

/// <reference types="node" />
import { Http } from "./http";
import { ClientResponse, RequestOptions } from "./types";
import CircuitBreaker from "opossum";
import http from "http";
declare class Client {
private http;
static circuits: Map<string, CircuitBreaker<any, ClientResponse>>;
static reporter: any;
constructor(http: Http);
metricsStream(_: http.IncomingMessage, response: http.ServerResponse): void;
request(name: string, url: string, options?: RequestOptions): Promise<ClientResponse>;

@@ -13,0 +9,0 @@ private createCircuit;

@@ -7,4 +7,2 @@ "use strict";

const opossum_1 = __importDefault(require("opossum"));
const opossum_hystrix_1 = __importDefault(require("opossum-hystrix"));
const enums_1 = require("./enums");
class Client {

@@ -14,14 +12,2 @@ constructor(http) {

}
metricsStream(_, response) {
response.writeHead(200, {
'content-type': enums_1.CONTENT_TYPE.TextEventStream,
'cache-control': enums_1.CACHE_CONTROL.NoCache,
'connection': enums_1.CONNECTION.KeepAlive
});
response.write('retry: 10000\n');
response.write('event: connecttime\n');
opossum_hystrix_1.default
.stream
.pipe(response);
}
request(name, url, options) {

@@ -44,3 +30,2 @@ const circuit = Client.circuits.get(name) || this.createCircuit(name, options);

const circuit = new opossum_1.default(requestSender, Object.assign({ name }, options));
Client.reporter.add(circuit);
Client.circuits.set(name, circuit);

@@ -52,3 +37,2 @@ return circuit;

Client.circuits = new Map();
Client.reporter = new opossum_hystrix_1.default([]);
//# sourceMappingURL=client.js.map

3

dist/http.js

@@ -35,3 +35,4 @@ "use strict";

const request = requestProvider.client.request(options, response => {
compression_1.Compression.handle(response)
compression_1.Compression
.handle(response)
.then(body => resolve({

@@ -38,0 +39,0 @@ body,

{
"name": "supra-http",
"version": "1.0.7",
"version": "1.0.8",
"description": "Circuit breaking http client for NodeJs. And it is fast...",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -6,9 +6,41 @@ Documentation will be released soon.

## Installing
```bash
npm i supra-http
```
## Simple Usage
### Get
```js
client.request('browsingConfigurationRequest', 'https://api.trendyol.com/mwebbrowsinggw/', {
timeout: 300,
client.request('apiCallName', 'https://my-api/endpoint', {
method: 'get',
json: true
})
.then(response => console.log(response.json))
.catch(_ => console.log(_));
```
### Post
```js
client.request('apiCallName', 'https://my-api/endpoint', {
method: 'post',
body: {
test: true
},
json: true
})
.then(response => console.log(response.json))
.catch(_ => console.log(_));
```
### Circuit Breaking
```js
client.request('apiCallName', 'https://my-api/endpoint', {
timeout: 1000,
allowWarmUp: true,
errorThresholdPercentage: 50,
resetTimeout: 10000,
enabled: false,
enabled: true,
method: 'get',

@@ -20,1 +52,16 @@ json: true

```
You can read more about properties from [opossum](https://github.com/nodeshift/opossum).
### Decompression
Supra supports gzip and brotli decompressions over zlib. So it requires at least NodeJs 10.17.x
### Benchmarks
```
supra with circuit x 8,779 ops/sec ±3.31% (76 runs sampled)
supra without circuit x 8,625 ops/sec ±4.68% (68 runs sampled)
requestretry x 3,672 ops/sec ±7.24% (67 runs sampled)
request x 5,092 ops/sec ±4.42% (73 runs sampled)
native http request 1.0 x 9,874 ops/sec ±5.82% (67 runs sampled)
native http request 1.1 x 9,681 ops/sec ±6.36% (73 runs sampled)
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet