Skip to content

Expose internal HttpClient #7148

@esd-thg

Description

@esd-thg

Is your feature request related to a problem? Please describe the problem.

Sometimes Kiota doesn't handle certain scenarios or generates incorrect "stuff" for an endpoint.
In these cases it would be handy to be able to access the HttpClient Kiota uses so we can manually make the request.
I'm expecting the HttpClient we get from Kiota to have the configured baseurl and authentication.

Client library/SDK language

Csharp

Describe the solution you'd like

public async Task GetAsync()
{
  // doesn't work - waiting on #7147
  // await _client.Tests.GetAsync(x => x.Headers.Add(HeaderNames.Accept, MediaTypeNames.Application.Octet));

  // workaround until fixed
  var httpClient = _client.HttpClient;
  // DefaultRequestHeaders might not be correct usage
  httpClient.DefaultRequestHeaders.Add(HeaderNames.Accept, MediaTypeNames.Application.Octet);
  var stream = await httpClient.GetStreamAsync("/tests");
  ...
}

Additional context

If DefaultRequestHeaders isn't the correct way to use the http client from Kiota then please make it easy to add headers to a single request.
Using HttpRequestMessage and SendAsync is tedious :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:featureNew experience request

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions