Skip to content

Commit 7f14f50

Browse files
authored
Use JSON string syntax for PATCH op (#482)
1 parent 3b52bf2 commit 7f14f50

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

8.0/BlazorWebAppCallWebApi/BlazorApp.slnLaunch.user

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
[
22
{
3-
"Name": "New Profile",
3+
"Name": "Start Solution",
44
"Projects": [
55
{
6-
"Name": "Backend\\Backend.csproj",
7-
"Action": "StartWithoutDebugging",
8-
"DebugTarget": ""
6+
"Path": "Backend\\Backend.csproj",
7+
"Action": "StartWithoutDebugging"
98
},
109
{
11-
"Name": "BlazorApp\\BlazorApp\\BlazorApp.csproj",
12-
"Action": "Start",
13-
"DebugTarget": ""
10+
"Path": "BlazorApp\\BlazorApp\\BlazorApp.csproj",
11+
"Action": "Start"
1412
}
1513
]
1614
}

8.0/BlazorWebAppCallWebApi/BlazorApp/BlazorApp.Client/Pages/CallTodoWebApiCsrPatch.razor

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/call-todo-web-api-csr-patch"
22
@rendermode InteractiveWebAssembly
3+
@using System.Diagnostics.CodeAnalysis
34
@using System.Text.Json
45
@using System.Text.Json.Serialization
56
@using Microsoft.AspNetCore.JsonPatch
@@ -40,6 +41,9 @@ else
4041
private PersistingComponentStateSubscription persistingSubscription;
4142
private HttpClient? client;
4243

44+
[StringSyntax(StringSyntaxAttribute.Json)]
45+
private const string patchOperation = """[{"operationType":2,"path":"/IsComplete","op":"replace","value":true}]""";
46+
4347
protected override async Task OnInitializedAsync()
4448
{
4549
client = ClientFactory.CreateClient("WebAPI");
@@ -76,7 +80,7 @@ else
7680
{
7781
await client.PatchAsJsonAsync(
7882
$"todoitems/{id}",
79-
"[{\"operationType\":2,\"path\":\"/IsComplete\",\"op\":\"replace\",\"value\":true}]");
83+
patchOperation);
8084
await GetTodoItems();
8185
}
8286
}

9.0/BlazorWebAppCallWebApi/BlazorApp.slnLaunch.user

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
[
22
{
3-
"Name": "New Profile",
3+
"Name": "Start Solution",
44
"Projects": [
55
{
6-
"Name": "Backend\\Backend.csproj",
7-
"Action": "StartWithoutDebugging",
8-
"DebugTarget": ""
6+
"Path": "Backend\\Backend.csproj",
7+
"Action": "StartWithoutDebugging"
98
},
109
{
11-
"Name": "BlazorApp\\BlazorApp\\BlazorApp.csproj",
12-
"Action": "Start",
13-
"DebugTarget": ""
10+
"Path": "BlazorApp\\BlazorApp\\BlazorApp.csproj",
11+
"Action": "Start"
1412
}
1513
]
1614
}

9.0/BlazorWebAppCallWebApi/BlazorApp/BlazorApp.Client/Pages/CallTodoWebApiCsrPatch.razor

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/call-todo-web-api-csr-patch"
22
@rendermode InteractiveWebAssembly
3+
@using System.Diagnostics.CodeAnalysis
34
@using System.Text.Json
45
@using System.Text.Json.Serialization
56
@using Microsoft.AspNetCore.JsonPatch
@@ -40,6 +41,9 @@ else
4041
private PersistingComponentStateSubscription persistingSubscription;
4142
private HttpClient? client;
4243

44+
[StringSyntax(StringSyntaxAttribute.Json)]
45+
private const string patchOperation = """[{"operationType":2,"path":"/IsComplete","op":"replace","value":true}]""";
46+
4347
protected override async Task OnInitializedAsync()
4448
{
4549
client = ClientFactory.CreateClient("WebAPI");
@@ -76,7 +80,7 @@ else
7680
{
7781
await client.PatchAsJsonAsync(
7882
$"todoitems/{id}",
79-
"[{\"operationType\":2,\"path\":\"/IsComplete\",\"op\":\"replace\",\"value\":true}]");
83+
patchOperation);
8084
await GetTodoItems();
8185
}
8286
}

0 commit comments

Comments
 (0)