Free Web Development Online Tutorials, Learn to Code
Learn Web Api Development, Web API C# Tutorial, Web API Security, Authentication, Authorization

Web API Delete Method Example C#

Remember to check the authorization before processing the delete request, so you must check if the request has come from authenticated user

Get the tbClient object where clientId match id,if matching client found then delete

Delete method in Web API

public HttpResponseMessage Delete(int id)            
    Client c = null;            

    // Get the tbClient object where clientId match id
    // if matching client found then delete
    // else send a message back saying "no client found"
    var returnMessage = Request.CreateResponse(HttpStatusCode.Accepted, c);
    returnMessage.Headers.Location = new Uri(Request.RequestUri + "/" + c.ClientId.ToString());
    return returnMessage;
catch (Exception ex)
    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);

Always keep the delete method type as HttpResponseMessage, so you can send customized response message back to user, so they know the end result of their call

Asp.Net Web API Delete Example

C# web service interview questions

Asp.Net Core C# Examples | Join Asp.Net MVC Course