-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add extension methods for HttpClient that allow serialization from/to JSON #32937
Comments
@terrajobst you linked 2x the same issue. Does it have to go through API review first? |
Why add these as extension methods to HttpClient? Why not just add them as regular methods to HttpClient? |
Clipboard is hard man! Fixed.
We did a brief run in a smaller group; at this point we should go ahead with the implementation first to see what issues we encounter and do the API review after with the complete API set and all modifications we made since then. |
Good question, this was discussed. Basically it goes like this: do we want HttpClient to depend on the JSON serializer? I think the answer is no; serializers come and go, much more than networking APIs. We concluded these should sit on top. This also allows customers to use either this one or the existing ASP.NET formatters which will use JSON.NET. |
I see you set the milestone to 5.0. Please note that we need to ship a preview by Build; it looks like we don't have a milestone for that. Should we? |
@terrajobst unless we have more than 5-10 issues tracking as must have for Build, I don't think it makes sense to create milestone/label. |
The verbs are also inconsistent with current naming. Something to consider:
Otherwise I think these APIs look good. I used the Formatting assembly extensively in a past life and would have had no problems migrating to this. |
I want to propose having these methods throw an exception when the response status code is not 2xx, and to include the HttpResponse in that exception, so that it can be used to pattern match the error and potentially deserialize the validation mesages, for example: try
{
return await client.GetJsonAsync<IReadOnlyCollection<Person>>("/people");
}
catch (HttpStatusCodeException e) when (e.StatusCode > 500)
{
//something bad happened at the server
Log(e);
throw;
}
catch (HttpStatusCodeException e) when (e.StatusCode > 400)
{
//something was wrong in the request
var validationMessage = await e.HttpResponse.Content.ReadAsJsonAsync<ValidationResult>();
BindValidationMesage(validationMessage);
return null;
}
catch (Exception e)
{
Log(e);
throw;
} |
I would expect the convenience methods (the ones not returning
|
Because I'm an idiot, I filed a new issue for today's API review (#33566 (comment)) instead of using this. I've marked this as API approved. I'll close the review one in favor of this. |
Seems like these comments weren't addressed even though this PR was merged? |
@IanKemp for
|
The spec is here:
https://github.com/dotnet/designs/blob/main/accepted/2020/json-http-extensions/json-http-extentions.md
Related issues:
The text was updated successfully, but these errors were encountered: