System.Net.Http.Json 9.0.0-rc.2.24473.5
About
Provides extension methods for System.Net.Http.HttpClient
and System.Net.Http.HttpContent
that facilitate serialization and deserialization of HTTP requests using System.Text.Json.
Key Features
- Extension methods for deserializing HTTP response JSON bodies.
- Extension methods for serializing HTTP request JSON bodies.
- Extension methods for deserializing JSON from
HttpContent
instances.
How to Use
using System.Net.Http.Json;
using var client = new HttpClient();
// Get the list of all books
Book[] books = await client.GetFromJsonAsync<Book[]>("https://api.contoso.com/books");
// Send a POST request to add a new book
var book = new Book(id: 42, "Title", "Author", publishedYear: 2023);
HttpResponseMessage response = await client.PostAsJsonAsync($"https://api.contoso.com/books/{book.id}", book);
if (response.IsSuccessStatusCode)
Console.WriteLine("Book added successfully.");
else
Console.WriteLine($"HTTP request failed with status code: {response.StatusCode}");
public record Book(int id, string title, string author, int publishedYear);
Main Types
The main types provided by this library are:
HttpClientJsonExtensions
HttpContentJsonExtensions
Additional Documentation
Related Packages
Feedback & Contributing
System.Net.Http.Json is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on System.Net.Http.Json.
Packages | Downloads |
---|---|
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
|
54 |
OpenIddict.Validation.SystemNetHttp
System.Net.Http integration package for the OpenIddict validation services.
|
45 |
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
|
11 |
OpenIddict.Validation.SystemNetHttp
System.Net.Http integration package for the OpenIddict validation services.
|
8 |
OpenIddict
Versatile OpenID Connect stack for .NET.
Note: this metapackage only references the generic core, server and validation packages.
To use these features on ASP.NET Core or OWIN/Katana/ASP.NET 4.x, reference the OpenIddict.AspNetCore or OpenIddict.Owin package.
|
8 |
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
|
8 |
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
|
7 |
OpenIddict.Validation.SystemNetHttp
System.Net.Http integration package for the OpenIddict validation services.
|
6 |
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
|
6 |
OpenIddict.Validation.SystemNetHttp
System.Net.Http integration package for the OpenIddict validation services.
|
5 |
https://go.microsoft.com/fwlink/?LinkID=799421
.NET Framework 4.6.2
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Threading.Tasks.Extensions (>= 4.5.4)
.NET 8.0
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
.NET 9.0
- No dependencies.
.NET Standard 2.0
- System.Text.Json (>= 9.0.0-rc.2.24473.5)
- System.Buffers (>= 4.5.1)
- System.Memory (>= 4.5.5)
- System.Threading.Tasks.Extensions (>= 4.5.4)