Skip to content

Commit af545c7

Browse files
committed
Adding table of contents to readme.
1 parent a2e6aac commit af545c7

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@
66
[![codecov](https://codecov.io/gh/CodingAleCR/http_interceptor/branch/master/graph/badge.svg)](https://codecov.io/gh/CodingAleCR/http_interceptor)
77
[![Star on GitHub](https://img.shields.io/github/stars/codingalecr/http_interceptor.svg?style=flat&logo=github&colorB=deeppink&label=stars)](https://github.com/codingalecr/http_interceptor)
88

9-
A middleware library that lets you modify requests and responses if desired. Based of on [http_middleware](https://github.com/TEDConsulting/http_middleware)
9+
This is a plugin that lets you intercept the different requests and responses from Dart's http package. You can use to add headers, modify query params, or print a log of the response.
1010

11-
## Getting Started
11+
## Quick Reference
1212

13-
This is a plugin that lets you intercept the different requests and responses from Dart's http package. You can use to add headers, modify query params, or print a log of the response.
13+
- [Installation](#installation)
14+
- [Usage](#usage)
15+
- [Building your own interceptor](#building-your-own-interceptor)
16+
- [Using your interceptor](#using-your-interceptor)
17+
- [Retrying requests](#retrying-requests)
18+
- [Having trouble? Fill an issue](#troubleshooting)
1419

15-
### Installing
20+
## Installation
1621

1722
Include the package with the latest version available in your `pubspec.yaml`.
1823

1924
```dart
2025
http_interceptor: any
2126
```
2227

23-
### Importing
28+
## Usage
2429

2530
```dart
2631
import 'package:http_interceptor/http_interceptor.dart';
2732
```
2833

29-
### Using `http_interceptor`
30-
31-
#### Building your own interceptor
34+
### Building your own interceptor
3235

3336
In order to implement `http_interceptor` you need to implement the `InterceptorContract` and create your own interceptor. This abstract class has two methods: `interceptRequest`, which triggers before the http request is called; and `interceptResponse`, which triggers after the request is called, it has a response attached to it which the corresponding to said request. You could use this to do logging, adding headers, error handling, or many other cool stuff. It is important to note that after you proccess the request/response objects you need to return them so that `http` can continue the execute.
3437

@@ -72,11 +75,11 @@ class WeatherApiInterceptor implements InterceptorContract {
7275
}
7376
```
7477

75-
#### Using your interceptor
78+
### Using your interceptor
7679

7780
Now that you actually have your interceptor implemented, now you need to use it. There are two general ways in which you can use them: by using the `HttpWithInterceptor` to do separate connections for different requests or using a `HttpClientWithInterceptor` for keeping a connection alive while making the different `http` calls. The ideal place to use them is in the service/provider class or the repository class (if you are not using services or providers); if you don't know about the repository pattern you can just google it and you'll know what I'm talking about. ;)
7881

79-
##### Using interceptors with Client
82+
#### Using interceptors with Client
8083

8184
Normally, this approach is taken because of its ability to be tested and mocked.
8285

@@ -107,7 +110,7 @@ class WeatherRepository {
107110
}
108111
```
109112

110-
##### Using interceptors without Client
113+
#### Using interceptors without Client
111114

112115
This is mostly the straight forward approach for a one-and-only call that you might need intercepted.
113116

@@ -137,9 +140,9 @@ class WeatherRepository {
137140
}
138141
```
139142

140-
#### Retrying requests (NEW 🎉)
143+
### Retrying requests
141144

142-
Sometimes you need to retry a request due to different circumstances, an expired token is a really good example. Here's how you could potentially implement an expired token retry policy with `http_interceptor`.
145+
**(NEW 🎉)** Sometimes you need to retry a request due to different circumstances, an expired token is a really good example. Here's how you could potentially implement an expired token retry policy with `http_interceptor`.
143146

144147
```dart
145148
class ExpiredTokenRetryPolicy extends RetryPolicy {
@@ -158,6 +161,6 @@ class ExpiredTokenRetryPolicy extends RetryPolicy {
158161

159162
You can also set the maximum amount of retry attempts with `maxRetryAttempts` property or override the `shouldAttemptRetryOnException` if you want to retry the request after it failed with an exception.
160163

161-
### Issue Reporting
164+
## Troubleshooting
162165

163166
Open an issue and tell me, I will be happy to help you out as soon as I can.

0 commit comments

Comments
 (0)