|
1 | | -# ngx-api-client |
2 | | - |
3 | | -A typed, interceptor-driven HTTP layer for Angular. |
| 1 | +<p align="center"> |
| 2 | + <a href="https://ismailza.github.io/ngx-api-client/"> |
| 3 | + <img src="https://ismailza.github.io/ngx-api-client/img/logo.svg" alt="" width="88" height="88"> |
| 4 | + </a> |
| 5 | +</p> |
| 6 | + |
| 7 | +<h1 align="center">ngx-api-client</h1> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + A typed, interceptor-driven HTTP layer for Angular. |
| 11 | +</p> |
| 12 | + |
| 13 | +<p align="center"> |
| 14 | + <a href="https://ismailza.github.io/ngx-api-client/"><strong>Documentation</strong></a> · |
| 15 | + <a href="https://www.npmjs.com/package/@ismailza/ngx-api-client"><strong>npm</strong></a> · |
| 16 | + <a href="https://ismailza.github.io/ngx-api-client/docs/getting-started/quick-start"><strong>Quick start</strong></a> · |
| 17 | + <a href="https://ismailza.github.io/ngx-api-client/docs/api/provide-api"><strong>API reference</strong></a> |
| 18 | +</p> |
| 19 | + |
| 20 | +<p align="center"> |
| 21 | + <a href="https://www.npmjs.com/package/@ismailza/ngx-api-client"><img src="https://img.shields.io/npm/v/@ismailza/ngx-api-client.svg" alt="npm version"></a> |
| 22 | + <a href="https://www.npmjs.com/package/@ismailza/ngx-api-client"><img src="https://img.shields.io/npm/dm/@ismailza/ngx-api-client.svg" alt="npm downloads"></a> |
| 23 | + <a href="https://ismailza.github.io/ngx-api-client/"><img src="https://img.shields.io/badge/docs-online-brightgreen.svg" alt="Documentation"></a> |
| 24 | + <a href="https://github.com/ismailza/ngx-api-client/actions/workflows/ci.yml"><img src="https://github.com/ismailza/ngx-api-client/actions/workflows/ci.yml/badge.svg" alt="CI"></a> |
| 25 | + <a href="https://github.com/ismailza/ngx-api-client/actions/workflows/release.yml"><img src="https://github.com/ismailza/ngx-api-client/actions/workflows/release.yml/badge.svg" alt="Release"></a> |
| 26 | + <a href="./LICENSE"><img src="https://img.shields.io/npm/l/@ismailza/ngx-api-client.svg" alt="License"></a> |
| 27 | +</p> |
4 | 28 |
|
5 | 29 | `HttpClient` gives you a request. It doesn't give you a _policy_ — where the base |
6 | 30 | URL comes from, how a failed response becomes something your components can |
@@ -43,17 +67,23 @@ export const appConfig: ApplicationConfig = { |
43 | 67 | retry: { maxRetries: 3, initialDelay: 1000 }, |
44 | 68 | }), |
45 | 69 | provideHttpClient( |
46 | | - withInterceptors([retryInterceptor, apiErrorInterceptor, apiSuccessInterceptor]), |
| 70 | + withInterceptors([apiErrorInterceptor, apiSuccessInterceptor, retryInterceptor]), |
47 | 71 | ), |
48 | 72 | ], |
49 | 73 | }; |
50 | 74 | ``` |
51 | 75 |
|
52 | 76 | Interceptors are registered by you, not by `provideApi()`, because **order |
53 | | -matters** and only you know what else is in the chain. Put an auth/bearer-token |
54 | | -interceptor first so retried requests get a fresh token; keep `retryInterceptor` |
55 | | -before `apiErrorInterceptor` so the error handler only sees failures that |
56 | | -survived every retry. |
| 77 | +matters** and only you know what else is in the chain. The first interceptor in |
| 78 | +the array is the outermost one: |
| 79 | + |
| 80 | +- Keep `apiErrorInterceptor` **before** `retryInterceptor`. It replaces the |
| 81 | + `HttpErrorResponse` with a plain `ApiError`, and `retryInterceptor` only |
| 82 | + retries `HttpErrorResponse`s — nest them the other way round and retry |
| 83 | + silently never fires. Outermost, it also reports one failure per operation |
| 84 | + rather than one per attempt. |
| 85 | +- Put an auth/bearer-token interceptor **last**, inside `retryInterceptor`, so |
| 86 | + each retried attempt is signed with a fresh token. |
57 | 87 |
|
58 | 88 | ## Usage |
59 | 89 |
|
@@ -257,14 +287,16 @@ matrix currently covers. |
257 | 287 |
|
258 | 288 | ## Contributing |
259 | 289 |
|
260 | | -```bash |
261 | | -npm install |
262 | | -npm test # 131 specs, vitest |
263 | | -npm run build |
264 | | -``` |
| 290 | +Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) before opening an issue or pull request. |
265 | 291 |
|
266 | | -Issues and pull requests are welcome. |
| 292 | +## Code of Conduct |
| 293 | + |
| 294 | +Please read our [Code of Conduct](CODE_OF_CONDUCT.md) to help us maintain a welcoming and inclusive community. |
267 | 295 |
|
268 | 296 | ## License |
269 | 297 |
|
270 | | -[MIT](../../LICENSE) © Ismail ZAHIR |
| 298 | +[MIT](./LICENSE) © Ismail ZAHIR |
| 299 | + |
| 300 | +## Support the Project |
| 301 | + |
| 302 | +If you find this library useful, consider giving it a ⭐ on GitHub. It helps others discover the project and motivates future development. |
0 commit comments