Skip to content

Commit 510bc2e

Browse files
committed
docs: add missing doc about axiosRef on http module page
1 parent ff76b4d commit 510bc2e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

content/faq/errors.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ During your development with NestJS, you may encounter various errors as you lea
66

77
Probably the most common error message is about Nest not being able to resolve dependencies of a provider. The error message usually looks something like this:
88

9-
```
9+
```text
1010
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument <unknown_token> at index [<index>] is available in the <module> context.
1111
1212
Potential solutions:
@@ -29,14 +29,14 @@ If the `unknown_token` above is the string `dependency`, you might have a circul
2929

3030
If you are in a monorepo setup, you may face the same error as above but for core provider called `ModuleRef` as a `<unknown_token>`:
3131

32-
```
32+
```text
3333
Nest can't resolve dependencies of the <provider> (?). Please make sure that the argument ModuleRef at index [<index>] is available in the <module> context.
3434
...
3535
```
3636

37-
This likely happens when your project end up loading two Node modules of the package `@nestjs/core`
37+
This likely happens when your project end up loading two Node modules of the package `@nestjs/core`, like this:
3838

39-
```
39+
```text
4040
.
4141
├── package.json
4242
├── apps
@@ -52,7 +52,7 @@ This likely happens when your project end up loading two Node modules of the pac
5252

5353
###### Fix for Yarn Workspaces
5454

55-
To circumvent that file structure in **Yarn** Workspaces, you can levearage on its [_nohoist_ feature](https://classic.yarnpkg.com/blog/2018/02/15/nohoist):
55+
To circumvent that file structure in **Yarn** Workspaces, you can leverage on its [_nohoist_ feature](https://classic.yarnpkg.com/blog/2018/02/15/nohoist):
5656

5757
```json
5858
{
@@ -67,7 +67,7 @@ To circumvent that file structure in **Yarn** Workspaces, you can levearage on i
6767

6868
Then, after `yarn install`, you'll get something like this:
6969

70-
```
70+
```text
7171
.
7272
├── package.json
7373
├── apps

content/techniques/http-module.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Next, inject `HttpService` using normal constructor injection.
3232
@@filename()
3333
@Injectable()
3434
export class CatsService {
35-
constructor(private httpService: HttpService) {}
35+
constructor(private readonly httpService: HttpService) {}
3636

3737
findAll(): Observable<AxiosResponse<Cat[]>> {
3838
return this.httpService.get('http://localhost:3000/cats');
@@ -131,3 +131,19 @@ HttpModule.registerAsync({
131131
useExisting: HttpConfigService,
132132
});
133133
```
134+
135+
#### Using Axios directly
136+
137+
If you think that `HttpModule.register`'s options are not enough for you, or if you just want to access the underlying Axios instance created by `@nestjs/axios`, you can access it via `HttpService#axiosRef` as follows:
138+
139+
```typescript
140+
@Injectable()
141+
export class CatsService {
142+
constructor(private readonly httpService: HttpService) {}
143+
144+
findAll(): Promise<AxiosResponse<Cat[]>> {
145+
return this.httpService.axiosRef.get('http://localhost:3000/cats');
146+
// ^ AxiosInstance interface
147+
}
148+
}
149+
```

0 commit comments

Comments
 (0)