BSiLabs / HttpTracer

MIT License
172 stars 13 forks source link

trouble getting started, Visual Studio + Refit example #49

Open adamfoneil opened 3 years ago

adamfoneil commented 3 years ago

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 commented 3 years ago

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.

DanielCauser commented 3 years ago

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

ChaseFlorell commented 3 years ago

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

DanielCauser commented 3 years ago

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

ChaseFlorell commented 3 years ago

Perhaps a Wiki in the new organization?

hamid-shaikh commented 2 years ago

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;
        }
    }