@joktec/http
v0.2.14
Published
JokTec - Http Client Service
Readme
@joktec/http
Axios-backed HTTP client package for JokTec applications.
@joktec/http wraps Axios with JokTec config parsing, retry behavior, proxy agent construction, optional cURL logging, request serialization, authorization helpers, upload helpers, and metrics.
What It Provides
HttpModuleglobal Nest module.HttpServicebuilt onAbstractClientService.- Request, response, upload, retry, proxy, auth, and metric models.
- HTTP exception types and proxy agent exports.
HttpProxyAgentandHttpsProxyAgentre-exports for advanced agent use.
Install
yarn add @joktec/httpUsage
import { HttpModule, HttpService } from '@joktec/http';
import { HttpMethod } from '@joktec/utils';
@Module({
imports: [HttpModule],
})
export class AppModule {}
await httpService.request({
method: HttpMethod.GET,
url: 'https://example.com',
});Authorization helpers can be passed per request:
await httpService.request({
method: HttpMethod.GET,
url: '/users/me',
authorization: {
bearerToken: accessToken,
},
});Config
Configure the http section in the application config. Multiple connections are selected with conId.
http:
conId: default
baseURL: https://api.example.com
timeout: 30000
maxRedirects: 3
curlirize: false
retryConfig:
retries: 3
shouldResetTimeout: true
retryDelay: 1000
httpMethodsToRetry: [GET, POST]
statusCodesToRetry:
- [500, 599]Proxy config can be set globally or per request:
http:
conId: proxy
baseURL: https://api.example.com
proxy:
protocol: http
host: localhost
port: 3128
keepAlive: trueGuidelines
- Prefer
baseURLin config and relative URLs in app services. - Use
serializer: truefor bracket-style array query serialization. - Keep third-party API response mapping in the consuming app.
- Avoid enabling
curlirizewhen logs could expose tokens or sensitive payloads. - Package tests mock Axios and proxy agents; use consumer scenarios for live endpoint checks.
Development
yarn lint --scope @joktec/http
yarn build --scope @joktec/http
yarn test --scope @joktec/http