RestSharp - DELETE request with async/await

CSharp · Console

/Program.cs

using RestSharp;
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
					
public class Program
{
	public static async Task Main()
	{
		// send DELETE request with RestSharp
        var client = new RestClient("https://testapi.jasonwatmore.com");
        var request = new RestRequest("products/1", Method.Delete);
		var response = await client.ExecuteAsync(request);

		// deserialize json string response to JsonNode object
		var data = JsonSerializer.Deserialize<JsonNode>(response.Content!)!;
		
		// output result
		Console.WriteLine($"""
		----------------
		json properties
		----------------
		message: {data["message"]}

		----------------
		raw json data
		----------------
		{data}

		----------------
		Documentation at https://jasonwatmore.com/c-restsharp-http-delete-request-examples-in-net
		""");
	}
}
;