Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
Update README

commit-id:9330f485
  • Loading branch information
ttshivers committed Apr 19, 2024
1 parent 969d3b8 commit d593f11
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ nestjs module that just doing little modification to the original and good **nes

## features
* axios - the most used package for http requests in npm and the one used by nestjs official http library.
* better axios stack trace - axios has an [open issue](https://github.com/axios/axios/issues/2387) about improvement of their stack trace.
in this library there is a default interceptor that will intercept the stack trace and will add data to it.
* promise based - most of us using the current http module that uses observable which we don't use most of the time
* promise based - most of us using the current http module that uses observable which we don't use most of the time
and in order to avoid it were just calling `.toPromise()` every http call.
* retries - in many cases we will want to retry a failing http call.
with observable we could just add the retry operator (rxjs) but with promises we need to implement this logic ourselves.
this package will make it easy for you, just pass `{ retries: NUMBER_OF_RETRIES }` in the config of the http module.
**more details in the configuration section**
## quick start

## quick start
### installing
Using npm:
```
Expand All @@ -34,7 +32,7 @@ $ yarn add nestjs-http-promise
```ts
import { HttpModule } from 'nestjs-http-promise'

@Module({
@Module({
imports: [HttpModule]
})
```
Expand All @@ -51,7 +49,7 @@ class Demo {
use the service:
```ts
public callSomeServer(): Promise<object> {
return this.httpService.get('http://fakeService')
return this.httpService.get('http://fakeService')
}
```
Expand All @@ -68,7 +66,7 @@ import { HttpModule } from 'nestjs-http-promise'
imports: [HttpModule.register(
{
timeout: 1000,
retries: 5,
retries: 10,
...
}
)]
Expand All @@ -77,7 +75,6 @@ import { HttpModule } from 'nestjs-http-promise'

### default configuration
* default config of axios-retry : https://github.com/softonic/axios-retry#options
* better axios stack trace is added by default, you can turn it off by passing the **isBetterStackTraceEnabled** to false.

## async configuration
When you need to pass module options asynchronously instead of statically, use the `registerAsync()` method **just like in nest httpModule**.
Expand All @@ -88,14 +85,14 @@ you have a couple of techniques to do it:
HttpModule.registerAsync({
useFactory: () => ({
timeout: 1000,
retries: 5,
retries: 10,
...
}),
});
```

* using class

```ts
HttpModule.registerAsync({
useClass: HttpConfigService,
Expand All @@ -109,13 +106,13 @@ class HttpConfigService implements HttpModuleOptionsFactory {
const configurationData = await someAsyncMethod();
return {
timeout: configurationData.timeout,
retries: 5,
retries: 10,
...
};
}
}
```
If you want to reuse an existing options provider instead of creating a copy inside the HttpModule,
If you want to reuse an existing options provider instead of creating a copy inside the HttpModule,
use the useExisting syntax.
```ts
HttpModule.registerAsync({
Expand Down

0 comments on commit d593f11

Please sign in to comment.