-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# Netcore WebRequest and HttpClient functionality #8821
C# Netcore WebRequest and HttpClient functionality #8821
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
d7f9c5f
to
cbabf1c
Compare
I think this is at a point now where it is ready to be reviewed. It still doesn't work with Blazor but it should work with Unity, I'll test that later today. In general I think a separate generator such as @shibayan or @devhl-labs has been working on might be needed to fully support Blazor because quite a few options simply aren't possible there. |
Thanks for the PR. I played with it locally and it looks very good to start with 👍 I'll merge it so that users can try it out in the upcoming 5.1.0 release (this month or next), and will submit PRs to further improve it (e.g. README, petstore integration tests in CI, etc) |
@@ -19,18 +19,28 @@ using System.Web; | |||
{{/netStandard}} | |||
using Newtonsoft.Json; | |||
using Newtonsoft.Json.Serialization; | |||
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs; | |||
{{#useRestSharp}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create a separate ApiClient.mustache just for httpclient
library similar to how we support multiple HTTP libraries in other client generators as too many {{#useRestSharp}} ... {{/useRestSharp}}
etc make the template hard to maintain.
Thank you for this PR! I found one small issue as I was testing this out in 5.1.0. I noticed that a new HttpClient is created for each call. From https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient?view=net-5.0:
|
I would like to try out the new HttpClient generator but I don't really have a clue on how to enable the new generator with the cli. So far I've tried the following command: |
There are two versions of HttpClient, mine and Blackclaws. Mine only uses one instance of HttpClient that you pass in, however, it only supports basic requests and JWT tokens at the moment. Looks like Blackclaw's version may have made the 5.1 release, but mine didn't. I have a pr to add it though. @VincentNe try just |
Yes, this was indeed the case in order to be mostly a drop in replacement for restsharp. As creating new HttpClients for each request is indeed problematic in some cases there is now a new pull request to change this behaviour to be by default a static HttpClient for each ApiClient which however is also customizable from outside. |
Some great work here @Blackclaws. I have some feedback if you're interested:
|
This is WIP work tracking the addition of WebRequest and HttpClient as replacements for RestSharp, as some environments might find it undesirable to include an additional library (Unity, Blazor, etc.).
This is a bit orthogonal to the already open pull request and could be considered a different take on the subject:
#8331
It tries to keep as much of the original interface intact as possible. WebRequest more so than HttpClient which simply does not offer many of the customizations that WebRequest and RestSharp do.
You can try it out by setting the library to httpclient by cliswitch or adding:
library: httpclient
to the global config in the config file you're using. Should hopefully alleviate/fix #6800 and #853
If you also want to get rid of the dependency on Polly add
additionalProperties:
supportsRetry: false
aswell
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x
@mandrean @frankyjuang @shibayan