Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
anugotta authored Jun 26, 2024
1 parent 34a26fb commit cedd1ef
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,35 @@ Then, run flutter pub get to install the package.
Here’s an example of how to use `http_cyclic_mocks` in your project:

```import 'package:dio/dio.dart';
import 'package:mock_http_client/mock_http_client.dart';
```
import 'package:dio/dio.dart';
import 'package:http_cyclic_mocks/http_cyclic_mocks.dart';

void main() async {
final dio = Dio();
final mockHttpClient = MockHttpClient(dio);
final mockHttpClient = CyclicMockClient(dio);

mockHttpClient.addMockResponses('/route1', [
MockResponse(data: {'message': 'Route 1 - Response 1'}, statusCode: 200),
MockResponse(data: {'message': 'Route 1 - Response 2'}, statusCode: 200),
MockResponse(data: {'message': 'Not Found'}, statusCode: 200),
MockResponse(data: {'message': 'Route 1 - SUCCESS'}, statusCode: 200),
]);

mockHttpClient.addMockResponses('/route2', [
MockResponse(data: {'message': 'Route 2 - Response 1'}, statusCode: 200),
MockResponse(data: {'message': 'Route 2 - Response 2'}, statusCode: 200),
MockResponse(data: {'message': 'Route 2 - Response 3'}, statusCode: 200),
MockResponse(data: {'message': 'Error Response'}, statusCode: 400),
MockResponse(data: {'message': 'Route 2 - SUCCESS'}, statusCode: 200),
MockResponse(data: {'message': 'ERROR - Route 2'}, statusCode: 404),
]);

// Example of making requests to see the cycling in action
for (int i = 0; i < 6; i++) {
final response1 = await dio.get('/route1');
print(response1.data);
final response2 = await dio.get('/route2');

try{
final response2 = await dio.get('/route2');
print(response2.data);
}catch(e){
print(e);
}
}
}
```
Expand All @@ -76,7 +81,7 @@ Contributions are welcome! Please follow these steps to contribute:
## License
This project is licensed under the MIT License - see the LICENSE file for details.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/anugotta/FlipTimerView/blob/master/LICENSE) file for details.
## Issues
Expand Down

0 comments on commit cedd1ef

Please sign in to comment.