CSharp · Console
using RestSharp;
using System;
using System.Text.Json;
using System.Text.Json.Nodes;
public class Program
{
public static void Main()
{
// send DELETE request with RestSharp
var client = new RestClient("https://testapi.jasonwatmore.com");
var request = new RestRequest("products/1", Method.Delete);
request.AddHeader("Authorization", "Bearer my-token");
request.AddHeader("My-Custom-Header", "foobar");
var response = client.Execute(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
""");
}
}