Add System.Net.Http.Json README
authorEirik Tsarpalis <eirik.tsarpalis@gmail.com>
Wed, 6 Sep 2023 15:40:23 +0000 (16:40 +0100)
committerViktor Hofer <viktor.hofer@microsoft.com>
Mon, 18 Sep 2023 14:24:48 +0000 (16:24 +0200)
src/libraries/System.Net.Http.Json/src/PACKAGE.md

index 2709a6e..5c08490 100644 (file)
@@ -1,44 +1,50 @@
 ## About
 
-<!-- A description of the package and where one can find more documentation -->
+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.
 
-## Key Features
+## How to Use
 
-<!-- The key features of this package -->
+```C#
+using System.Net.Http.Json;
 
-*
-*
-*
+using var client = new HttpClient();
 
-## How to Use
+// Get the list of all books
+Book[] books = await client.GetFromJsonAsync<Book[]>("https://api.contoso.com/books");
 
-<!-- A compelling example on how to use this package with code, as well as any specific guidelines for when to use the package -->
+// 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);
 
-## Main Types
+if (response.IsSuccessStatusCode)
+    Console.WriteLine("Book added successfully.");
+else
+    Console.WriteLine($"HTTP request failed with status code: {response.StatusCode}");
 
-<!-- The main types provided in this library -->
+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
 
-<!-- Links to further documentation. Remove conceptual documentation if not available for the library. -->
-
-* [Conceptual documentation](https://learn.microsoft.com/en-us/dotnet/standard/serialization/**LIBRARYNAME**/overview)
-* [API documentation](https://learn.microsoft.com/en-us/dotnet/api/**LIBRARYNAME**)
+* [API documentation](https://learn.microsoft.com/dotnet/api/system.net.http.json)
 
 ## Related Packages
 
-<!-- The related packages associated with this package -->
+* [System.Text.Json](https://www.nuget.org/packages/System.Text.Json)
 
 ## Feedback & Contributing
 
-<!-- How to provide feedback on this package and contribute to it -->
-
-**LIBRARY NAME** is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).
\ No newline at end of file
+**System.Net.Http.Json** is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).