Example project on how to use SystemTextJsonPatch library to provide HTTP PATCH support for your API.
This example is written using Minimal API and targets .NET 6.
To get this working in your project:
- Install
SystemTextJsonPatchlibrary.dotnet add package SystemTextJsonPatch - Add the Converter to System.Text.Json in
Program.csvia (e.g. see Program.cs):using SystemTextJsonPatch.Converters; ... builder.Services.Configure<JsonOptions>(o => o.SerializerOptions.Converters.Add(new JsonPatchDocumentConverterFactory()));
Check examples.http for examples of the HTTP Patch calls.
You can actually run the examples, by opening examples.http in VS Code using the Rest Client Extension.
- HTTP Patch support in Minimal API is provided by the
MapPatchendpoint registration method. In .NET 6 that is using an extension method (see Extensions.cs). This is a built-in method from .NET 7. - HTTP Patch support is provided by the built-in
[HttpPatch]attribute for Controller based action methods.