Abdelazeem777 / requests_inspector

MIT License
11 stars 18 forks source link

Create interceptor for dio package #1

Closed binSaed closed 2 years ago

binSaed commented 2 years ago

instead of adding the request by your hand

InspectorController().addNewRequest(
    RequestDetails(
        requestName: requestName,
        requestMethod: RequestMethod.GET,
        url: apiUrl,
        statusCode: responseStatusCode,
        responseBody: responseData,
        sentTime: DateTime.now(),
        ),
    );

u can make an interceptor for the DIO package and the user will add this one time like this

dio.interceptors.add(RequestsInspector());
Abdelazeem777 commented 2 years ago

But then It will work only for Dio package only, what about the other http request packages?

binSaed commented 2 years ago

@Abdelazeem777

user will have 2 optional 1-add interceptor if he uses dio 2- manually use InspectorController().addNewRequest

I think interceptor will reduce code and more clear if used in large apps

binSaed commented 2 years ago

@maxzod ur opinion?

maxzod commented 2 years ago

why not listen for all the requests like the devtools does ?

iam working on a queen_dev_tools and stuck on the part of how to listen for any IO request 😢 also the dio interceptor would be great but it will make it depend on dio still less code to right if you intended to use dio in your application

still fixing the root problem and listen to any IO request will be the best solution also it will provide more options to observe like socket and local network requests not just the used API

Abdelazeem777 commented 2 years ago

@AbdOoSaed

I think it's a very good idea to have both options, so I will consider adding this feature for the next version ISA.

Abdelazeem777 commented 2 years ago

@maxzod

It would be great because the widget will log the http requests by itself but I kinda hard to achieve because of listening to the IO http requests, as we discussed lately.

So if you have any suggestions to do so, please don't hesitate.

Abdelazeem777 commented 2 years ago

This feature is added.

Now you can pass RequestsInspectorInterceptor to Dio instead of using normal InspectorController.addRequest method.

ex.

final dio = Dio()..interceptors.add(RequestsInspectorInterceptor());