{"id":20880950,"url":"https://github.com/dev-ashishk/nest-axios-http","last_synced_at":"2025-05-12T16:32:24.691Z","repository":{"id":245002775,"uuid":"816973391","full_name":"dev-ashishk/nest-axios-http","owner":"dev-ashishk","description":"A NestJS module for simplified HTTP requests using Axios with dynamic configuration, logging, and interceptor support.","archived":false,"fork":false,"pushed_at":"2024-11-26T18:12:17.000Z","size":93,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-30T03:37:57.861Z","etag":null,"topics":["axios","axios-nestjs","http","nestjs","nestjs-axios","nestjs-backend","nestjs-http","typescript","utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@nodeflip/nest-axios-http","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dev-ashishk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-18T18:53:30.000Z","updated_at":"2025-01-16T16:27:31.000Z","dependencies_parsed_at":"2025-01-25T19:03:12.053Z","dependency_job_id":"5527c156-2196-459c-841a-980ac1e4df1b","html_url":"https://github.com/dev-ashishk/nest-axios-http","commit_stats":null,"previous_names":["nodeflip/nest-axios-http","dev-ashishk/nest-axios-http"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-axios-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-axios-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-axios-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dev-ashishk%2Fnest-axios-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dev-ashishk","download_url":"https://codeload.github.com/dev-ashishk/nest-axios-http/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253777011,"owners_count":21962609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["axios","axios-nestjs","http","nestjs","nestjs-axios","nestjs-backend","nestjs-http","typescript","utility"],"created_at":"2024-11-18T07:22:52.732Z","updated_at":"2025-05-12T16:32:24.685Z","avatar_url":"https://github.com/dev-ashishk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![test workflow](https://github.com/nodeflip/nest-axios-http/actions/workflows/test.yml/badge.svg)\n[![npm version](https://badge.fury.io/js/%40nodeflip%2Fnest-axios-http.svg)](https://badge.fury.io/js/%40nodeflip%2Fnest-axios-http)\n[![downloads](https://img.shields.io/npm/dm/@nodeflip/nest-axios-http.svg)](https://www.npmjs.com/package/@nodeflip/nest-axios-http)\n\n# @nodeflip/nest-axios-http\n\n## Description\n\n`@nodeflip/nest-axios-http` is a NestJS module that simplifies HTTP requests using Axios within NestJS applications. It provides an easy-to-use interface for making HTTP calls while integrating seamlessly with NestJS dependency injection and module system.\n\n## Features\n\n- **Simplified HTTP Requests:** Easily make HTTP requests with Axios using a service-oriented approach.\n- **Dependency Injection:** Utilize NestJS's powerful dependency injection system to manage HTTP service instances.\n- **Customization Options:** Customize Axios instance configuration, logging, request/response interceptors, and error handling.\n- **Dynamic Module Configuration:** Dynamically configure HTTP services based on module options using `forRoot`, `forFeature`, and `forFeatureWithProvider` methods.\n\n## Benefits\n\n- **Integration with NestJS:** Seamlessly integrates with NestJS architecture, making it easy to manage HTTP services as injectable dependencies.\n- **Modular Design:** Allows for dynamic module configuration, enabling multiple HTTP service instances with different configurations within a single NestJS application.\n- **Logging and Interceptors:** Built-in support for custom logging and request/response interceptors, providing flexibility in handling HTTP interactions.\n- **Named Services:** Supports injecting named HTTP services using `serviceName` for different configurations or service instances within the same application.\n\n## Installation\n\n```bash\nnpm install @nodeflip/nest-axios-http\n```\n\n## Usage\n\n### Importing the Module\n\nImport `HttpModule` into your NestJS application's module (`AppModule`, for example).\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { HttpModule } from '@nodeflip/nest-axios-http';\n\n@Module({\n  imports: [\n    HttpModule.forRoot({\n      config: {\n        baseURL: 'https://api.example.com',\n        enableLogging: true,\n        onRequest: (config) =\u003e {\n          // Customize request logging or modifications\n          return config;\n        },\n        onResponse: (response) =\u003e {\n          // Customize response logging or modifications\n          return response;\n        },\n        onError: (error) =\u003e {\n          // Customize error handling or logging\n          return Promise.reject(error);\n        },\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n### Using HTTP Service\n\nInject `HttpService` into your NestJS components or services to make HTTP requests.\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { HttpService } from '@nodeflip/nest-axios-http';\nimport { AxiosResponse } from 'axios';\n\n@Injectable()\nexport class MyService {\n  constructor(private readonly httpService: HttpService) {}\n\n  async fetchData(): Promise\u003cAxiosResponse\u003cany\u003e\u003e {\n    return this.httpService.get('/data');\n  }\n\n  async postData(data: any): Promise\u003cAxiosResponse\u003cany\u003e\u003e {\n    return this.httpService.post('/data', data);\n  }\n}\n```\n\n### Injecting Named HTTP Services\n\nYou can inject named HTTP services using the `serviceName` option and the `@Inject` decorator.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { HttpModule } from '@nodeflip/nest-axios-http';\n\n@Module({\n  imports: [\n    HttpModule.forRoot({\n      serviceName: 'CustomHttpService',\n      config: {\n        baseURL: 'https://api.example.com',\n        enableLogging: true,\n        onRequest: (config) =\u003e {\n          // Customize request logging or modifications\n          return config;\n        },\n        onResponse: (response) =\u003e {\n          // Customize response logging or modifications\n          return response;\n        },\n        onError: (error) =\u003e {\n          // Customize error handling or logging\n          return Promise.reject(error);\n        },\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n```\n\n```typescript\nimport { Injectable, Inject } from '@nestjs/common';\nimport { HttpService } from '@nodeflip/nest-axios-http';\nimport { AxiosResponse } from 'axios';\n\n@Injectable()\nexport class AnotherService {\n  constructor(\n    @Inject('CustomHttpService') private readonly customHttpService: HttpService,\n    @Inject(HttpService) private readonly defaultHttpService: HttpService,\n  ) {}\n\n  async fetchDataFromCustomService(): Promise\u003cAxiosResponse\u003cany\u003e\u003e {\n    return this.customHttpService.get('/custom-data');\n  }\n\n  async fetchDataFromDefaultService(): Promise\u003cAxiosResponse\u003cany\u003e\u003e {\n    return this.defaultHttpService.get('/default-data');\n  }\n}\n```\n\n### Custom Logging and Interceptors\n\nYou can customize logging and request/response interceptors by providing `logger` and `config` options during module initialization.\n\n```typescript\nimport { Logger } from \"@nestjs/common\";\nimport { Module } from \"@nestjs/common\";\nimport { HttpModule } from \"@nodeflip/nest-axios-http\";\n\nconst customLogger = new Logger(\"CustomLogger\");\n\n@Module({\n  imports: [\n    HttpModule.forRoot({\n      logger: customLogger, // Custom logger instance\n      config: {\n        baseURL: \"https://api.example.com\",\n        enableLogging: true,\n        onRequest: (config) =\u003e {\n          // Customize request logging or modifications\n          return config;\n        },\n        onResponse: (response) =\u003e {\n          // Customize response logging or modifications\n          return response;\n        },\n        onError: (error) =\u003e {\n          // Customize error handling or logging\n          return Promise.reject(error);\n        },\n      },\n    }),\n  ],\n})\nexport class AppModule {}\n\n```\n### Configuring Multiple HTTP Services\n\nYou can configure multiple HTTP services using an array of options with forFeature.\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { HttpModule } from \"@nodeflip/nest-axios-http\";\n\n@Module({\n  imports: [\n    HttpModule.forFeature([\n      {\n        serviceName: \"HTTP_SERVICE_2\",\n        config: {\n          baseURL: \"https://api.service1.com\",\n          enableLogging: true,\n          onRequest: (config) =\u003e {\n            // Optional: Customize request logging or modifications\n            return config;\n          },\n          onResponse: (response) =\u003e {\n            // Optional: Customize response logging or modifications\n            return response;\n          },\n          onError: (error) =\u003e {\n            // Optional: Customize error handling or logging\n            return Promise.reject(error);\n          },\n        },\n      },\n      {\n        serviceName: \"HTTP_SERVICE_2\",\n        config: {\n          baseURL: \"https://api.service2.com\",\n          enableLogging: true,\n          onRequest: (config) =\u003e {\n            // Optional: Customize request logging or modifications\n            return config;\n          },\n          onResponse: (response) =\u003e {\n            // Optional: Customize response logging or modifications\n            return response;\n          },\n          onError: (error) =\u003e {\n            // Optional: Customize error handling or logging\n            return Promise.reject(error);\n          },\n        },\n      },\n    ]),\n  ],\n})\nexport class AppModule {}\n\n```\n\n### Inject other modules and use it\n\n```typescript\n\nimport { Module } from \"@nestjs/common\";\nimport { HttpModule } from \"@nodeflip/nest-axios-http\";\n\n@Module({\n  imports: [\n    HttpModule.forFeatureAsync({\n      logger: customLogger, // Custom logger instance\n      serviceName: 'MyService', // Service name for logging\n      inject: [ConfigService],\n      useFactory: (configService: ConfigService) =\u003e {\n        return {\n          baseURL: configService.get('API_BASE_URL'),\n          enableLogging: configService.get('ENABLE_LOGGING'),\n        }\n      }\n    }),\n  ],\n})\n\n```\n## License\n\nThis package is [MIT licensed](LICENSE).\n\n## Issues\n\nFor any issues, bugs, or feature requests, please [file an issue](https://github.com/nodeflip/nest-axios-http/issues) on GitHub.\n\n## Repository\n\nFind this package on [npm](https://npmjs.com/@nodeflip/nest-axios-http).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-ashishk%2Fnest-axios-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdev-ashishk%2Fnest-axios-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdev-ashishk%2Fnest-axios-http/lists"}