Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bimedia-fr/architect-http-client
Architect module for making http calls
https://github.com/bimedia-fr/architect-http-client
Last synced: 8 days ago
JSON representation
Architect module for making http calls
- Host: GitHub
- URL: https://github.com/bimedia-fr/architect-http-client
- Owner: bimedia-fr
- License: apache-2.0
- Created: 2024-10-25T13:24:08.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-19T17:36:09.000Z (about 2 months ago)
- Last Synced: 2024-12-20T15:57:28.252Z (16 days ago)
- Language: JavaScript
- Size: 125 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# architect-http-client
Architect module for making http calls### Installation
```sh
npm install --save architect-http-client
```### Config Format
```js
module.exports = [{
packagePath: "architect-http-client",
// Choose your dispatcher name
request: {
baseUrl: 'http://localhost:8006',
disableDebugLog: true, disableInfoLog: true
},
client: {
baseUrl: 'http://localhost:8006',
disableDebugLog: true, disableInfoLog: true,
clientOptions: {
headersTimeout: 3e3, connectTimeout: 3e3, bodyTimeout: 3e3, connect: { timeout: 3e3 }
}
},
pool: {
baseUrl: 'http://localhost:8006',
disableDebugLog: true, disableInfoLog: true,
poolOptions: {
connections: 2, headersTimeout: 3e3, connectTimeout: 3e3, bodyTimeout: 3e3, connect: { timeout: 3e3 }
}
}
}];
```
Option list by dispatcher
* `baseUrl`: (string) Base URL with port if necessary,
* `requestOptions`: (Object) Set request option for every calls (See Undici request options),
* `clientOptions`: (Object) Instantiate a client dispatcher with options (See Undici client class),
* `poolOptions`: (Object) Instantiate a pool dispatcher with options (See Undici pool class),
* `throwOnError`: (bool) throw an error if response.ok is false (statusCode out of 2XX),
* `customIdHeader`: (Object) { customIdHeader: 'x-req-id' } set custom request ID header if request ID,
* `disableDebugLog`: (bool) disable service debug logs,
* `disableInfoLog`: (bool) disable service infos logs### Usage
Configure Architect with `config.js` :
```js
module.exports = [{
packagePath: "architect-http-client",
myCustomPool: {
baseUrl: 'http://xxxx:xxxx',
disableDebugLog: true,
disableInfoLog: true,
poolOptions: {
connections: 2, headersTimeout: 3e3, connectTimeout: 3e3, bodyTimeout: 3e3, connect: { timeout: 3e3 }
}
}
}];
```Perform http call
```js
var path = require('path');
var architect = require("architect");var configPath = path.join(__dirname, "config.js");
var config = architect.loadConfig(configPath);architect.createApp(config, async function (err, app) {
if (err) {
throw err;
}
console.log("app ready");
let http = app.getService('httpService').myCustomPool;
let res = await http.get('/api/json-get');
console.log(res);
/* res
{
ok: true,
statusCode: 200,
headers: {},
body: { result: 'OK' },
trailers: {},
opaque: null,
context: {}
}
*/
});
```See Undici documentation for advanced usages.
- https://undici.nodejs.org/#/
- https://github.com/nodejs/undici