Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update README #342

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading