HttpTracer icon indicating copy to clipboard operation
HttpTracer copied to clipboard

trouble getting started, Visual Studio + Refit example

Open adamfoneil opened this issue 4 years ago • 6 comments

Hi there, I found your library in the course of trying to troubleshoot a Refit issue. It's one of those cases where I can make it work in Postman, but I'm not sure how to reproduce it correctly for Refit. The issue is I'm not seeing any trace output in the Debug window when I run my project. I've made a little walkthrough:

https://1drv.ms/u/s!AvguHRnyJtWMmeh7C8wHrd7X8BbDyA?e=tcCcNZ

Here's my relevant code: https://github.com/adamfoneil/GitHubApi/blob/master/MicropubApi.Library/MicropubApiClient.cs#L17

adamfoneil avatar Dec 18 '20 12:12 adamfoneil

I went ahead and used Fiddler to get debug my immediate issue. The line number URL above is no longer relevant because I removed the trace stuff, but I'm still interested to hear your feedback.

adamfoneil avatar Dec 18 '20 13:12 adamfoneil

Hey Adam, I've setup our lib with Refit before, I will write something up and share, so you can check out too.

DanielCauser avatar Jan 14 '21 22:01 DanielCauser

@DanielCauser did you ever get around to doing your writeup?

ChaseFlorell avatar Jun 23 '21 20:06 ChaseFlorell

I did, and I will bring this up here this weekend.

DanielCauser avatar Aug 19 '21 18:08 DanielCauser

Perhaps a Wiki in the new organization?

ChaseFlorell avatar Aug 19 '21 18:08 ChaseFlorell

Refit + HttpTracer Example

Checkout below steps for Refit https://gist.github.com/hamid-shaikh/24d93419f9b5313685c4dfc40f4b59dc

For HttpTracer implementation just simply replace HttpClient creation with below snippet

    HttpClient restClient;
    HttpClient RestClient
    {
        get
        {
            if (restClient != null)
                return restClient;

            var builder = new HttpHandlerBuilder();

            builder.AddHandler(new AppMessageHandler());

            var tracer = builder.Build();

            restClient = new HttpClient(tracer)
            {
                BaseAddress = new Uri(GetBaseAddress()),//App Base URI
                Timeout = TimeSpan.FromSeconds(APIConstants.Timeout)//Timeout time for HTTP Request
            };

            restClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            return restClient;
        }
    }

hamid-shaikh avatar Aug 29 '22 08:08 hamid-shaikh