refit http logging example


This is based off this blog.  I added some a minimal api version of it. You can check it out here

Some of the pitfalls that I encounter are documented in the code for example, 

Trying to setup my HttpMessageHandler that work for me.

//// Adding our new handler here
refitClientBuilder.AddHttpMessageHandler(serviceProvider
  => new HttpLoggingHandler(serviceProvider.GetRequiredService<ILogger<HttpLoggingHandler>>()));
refitClientBuilder.Services.AddSingleton<HttpLoggingHandler>();

// doésn't work for me
//refitClientBuilder.AddHttpMessageHandler<HttpLoggingHandler>();


Using the injected service version of it

app.MapGet("/hello", async (IRandomUserAPI client) =>
{
    // no don't try this - use DI instead
    //var randomClient = RestService.For<IRandomUserAPI>("https://randomuser.me");
       
    var result = await client.GetUser();
    Console.WriteLine(result.Results[0].Gender);
    return result;

});




 

Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm