microsoft / microsoft/kiota

Expose internal HttpClient

Open
#7,148 1 comment 0 reactions 0 assignees View on GitHub
Csharp status:waiting-for-triage type:feature
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

### 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

```cs
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 :)

Contributor guide

Open the contributing guide

Research direction

Start by tracing the C# client's current HttpClient configuration and the request path described here, including the base URL and authentication. Use #7147 as context, and consider both exposing the configured client and providing an easy way to add headers to a single request. Done means one of these supported approaches is clearly defined and usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.