0

I have problem with managing multiple actions on same route when trying to access HttpDelete controller method.

[Route("api/doctors/{id}/{type}")]
[HttpDelete]
public async Task<IHttpActionResult> Toggle(int id, string type)
{
    switch (type)
    {
        case "delete":
            return Ok(await Delete(id));
        case "disable":
            return Ok(await Disable(id));
        case "block":
            return Ok(await Block(id));
        default:
            return NotFound();
    }
}

Like this, I am using verbs in the route, but I like to avoid them. Can somebody tell me better way to manage them?

Janitor
  • 1
  • 1
  • And your problem is? – J.Salas Dec 22 '21 at 11:40
  • @J.Salas I like to try to avoid using verbs in the routes. As I know using verbs in routes is bad practice in RESTful API. – Janitor Dec 22 '21 at 12:35
  • I think you aren't, type seems a 'delete' method switch. (physical record delete), (just mark record as deleted) (just mark record as deleted for everyone but administrator) – J.Salas Dec 22 '21 at 12:40

1 Answers1

0

Look at this one -> Single controller with multiple GET methods in ASP.NET Web API

It is about HttpGet but I think you will get the same idea.

AchoVasilev
  • 454
  • 5
  • 15