requests_inspector
所属分类:WEB开发
开发工具:Dart
文件大小:0KB
下载次数:0
上传日期:2023-09-28 17:59:28
上 传 者:
sh-1993
说明: 请求检查器,,
(requests inspector,,)
文件列表:
.metadata (309, 2023-12-19)
CHANGELOG.md (4230, 2023-12-19)
LICENSE (1075, 2023-12-19)
analysis_options.yaml (313, 2023-12-19)
example/ (0, 2023-12-19)
example/.metadata (1222, 2023-12-19)
example/analysis_options.yaml (1453, 2023-12-19)
example/android/ (0, 2023-12-19)
example/android/app/ (0, 2023-12-19)
example/android/app/build.gradle (2231, 2023-12-19)
example/android/app/src/ (0, 2023-12-19)
example/android/app/src/debug/ (0, 2023-12-19)
example/android/app/src/debug/AndroidManifest.xml (378, 2023-12-19)
example/android/app/src/main/ (0, 2023-12-19)
example/android/app/src/main/AndroidManifest.xml (1786, 2023-12-19)
example/android/app/src/main/kotlin/ (0, 2023-12-19)
example/android/app/src/main/kotlin/com/ (0, 2023-12-19)
example/android/app/src/main/kotlin/com/example/ (0, 2023-12-19)
example/android/app/src/main/kotlin/com/example/example/ (0, 2023-12-19)
example/android/app/src/main/kotlin/com/example/example/MainActivity.kt (124, 2023-12-19)
example/android/app/src/main/res/ (0, 2023-12-19)
example/android/app/src/main/res/drawable-v21/ (0, 2023-12-19)
example/android/app/src/main/res/drawable-v21/launch_background.xml (438, 2023-12-19)
example/android/app/src/main/res/drawable/ (0, 2023-12-19)
example/android/app/src/main/res/drawable/launch_background.xml (434, 2023-12-19)
example/android/app/src/main/res/mipmap-hdpi/ (0, 2023-12-19)
example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png (544, 2023-12-19)
example/android/app/src/main/res/mipmap-mdpi/ (0, 2023-12-19)
example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png (442, 2023-12-19)
example/android/app/src/main/res/mipmap-xhdpi/ (0, 2023-12-19)
example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png (721, 2023-12-19)
example/android/app/src/main/res/mipmap-xxhdpi/ (0, 2023-12-19)
example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (1031, 2023-12-19)
example/android/app/src/main/res/mipmap-xxxhdpi/ (0, 2023-12-19)
example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (1443, 2023-12-19)
... ...
[![Stand With Palestine](https://raw.githubusercontent.com/TheBSD/StandWithPalestine/main/banner-no-action.svg)](https://thebsd.github.io/StandWithPalestine)
# requests_inspector
A Flutter package for **logging** API requests (**RESTful API** & **GraphQL**) requests and accessing it by **Shaking** your phone to get the `RequestsInspector` widget on your screen.
Also you can share the request details as (**Log** or **cURL** command) with your team to help them debug the API requests.
**Note:**
You can use `cURL` command to send the request again from your terminal or [Postman](https://www.postman.com/)
### First, add it at the top of your `MaterialApp` with `enabled: true`.
```dart
void main() {
runApp(const RequestsInspector(
enabled: true,
child: MyApp(),
));
}
```
### 1. RESTful API:
**Note:** Don't forget to `enable` it!
### Then, on your API request add a new `RequestDetails` using `RequestInspectorController` filled with the API data.
```dart
InspectorController().addNewRequest(
RequestDetails(
requestName: requestName,
requestMethod: RequestMethod.GET,
url: apiUrl,
queryParameters: params,
statusCode: responseStatusCode,
responseBody: responseData,
),
);
```
### OR, if you are using `Dio`, then you can just pass `RequestsInspectorInterceptor()` to `Dio.interceptors` and we are good to go .
```dart
final dio = Dio()..interceptors.add(RequestsInspectorInterceptor());
```
### Real Restful example
a. Normal `InspectorController().addNewRequest`.
```dart
Future
> fetchPosts() async {
final dio = Dio();
final params = {'userId': 1};
final response = await dio.get(
'https://jsonplaceholder.typicode.com/posts',
queryParameters: params,
);
final postsMap = response.data as List;
final posts = postsMap.map((postMap) => Post.fromMap(postMap)).toList();
InspectorController().addNewRequest(
RequestDetails(
requestName: 'Posts',
requestMethod: RequestMethod.GET,
url: 'https://jsonplaceholder.typicode.com/posts',
queryParameters: params,
statusCode: response.statusCode ?? 0,
responseBody: response.data,
),
);
return posts;
}
```
b. Using `RequestsInspectorInterceptor`.
```dart
Future> fetchPosts() async {
final dio = Dio()..interceptors.add(RequestsInspectorInterceptor());
final response = await dio.get('https://jsonplaceholder.typicode.com/posts');
final postsMap = response.data as List;
final posts = postsMap.map((postMap) => Post.fromMap(postMap)).toList();
return posts;
}
```
### Finlay, `Shake` your phone to get the `Inspector`
### 2. GraphQl:
To use `requests_inspector` with [graphql_flutter]('https://pub.dev/packages/graphql_flutter') library.
you jus need to wrap your normal `HttpLink` with our `GraphQLInspectorLink` and we are done.
**Example:**
```dart
Future> fetchPostsGraphQlUsingGraphQLFlutterInterceptor() async {
Future> fetchPostsGraphQlUsingGraphQLFlutterInterceptor() async {
final client = GraphQLClient(
cache: GraphQLCache(),
link: Link.split(
(request) => request.isSubscription,
GraphQLInspectorLink(WebSocketLink('ws://graphqlzero.almansi.me/api')),
GraphQLInspectorLink(HttpLink('https://graphqlzero.almansi.me/api')),
),
);
const query = r'''query {
post(id: 1) {
id
title
body
}
}''';
final options = QueryOptions(document: gql(query));
final result = await client.query(options);
if (result.hasException) {
log(result.exception.toString());
} else {
log(result.data.toString());
}
var post = Post.fromMap(result.data?['post']);
return [post];
}
```
### For Web, Windows, MacOS and Linux
Obviously, The shaking won't be good enough for those platforms
So you can specify `showInspectorOn` with `ShowInspectorOn.LongPress`.
```dart
void main() {
runApp(const RequestsInspector(
enabled: true,
showInspectorOn: ShowInspectorOn.LongPress
child: MyApp(),
));
}
```
OR, you can just pass `ShowInspectorOn.Both` to open the `Inspector` with `Shaking` or with `LongPress`.
```dart
void main() {
runApp(const RequestsInspector(
enabled: true,
showInspectorOn: ShowInspectorOn.Both
child: MyApp(),
));
}
```
## Some screenshots
## Future plans
- [x] Add support for `GraphQL`.
- [ ] Enhance the `GraphQL` request and response displaying structure.
- [ ] Improve the request tab UI and add expand/collapse for each data block.
- [ ] Add search inside the request details page.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
近期下载者:
相关文件:
收藏者: