0

I have a problem with ASP.NET WebAPI`. I wanted to keep in RESTful API, so I create some apis in one controller, such as:

  • GET /api/user/ - userslist
  • GET /api/user/{id} - a user
  • GET /api/user/{id}/books - get all books of the user
  • Delete /api/user/{id} - delete the user
  • Delete /api/user/{id}/books - delete users' books

All the Get methods works fine, but only one Delete method can work, when the other was called, it will got a 405 response. Could you help me ?

Thanks. here is my controller

[RoutePrefix("api/Car")]//AttributeRouting asp.net 4.0 (not 5.0)
public class CarController : ApiController
{
    public CarInfoPagedList GetCarInfos(int page = 0, int limit = 10)
    {  
        var list = new CarInfoPagedList();
        return list;
    }

    [HttpRoute("{id}")]
    public string GetCarById(string id, string time = " ") 
    {
        return "some";
    }


    [HttpRoute("{id}/runtime")]
    public CarState GetCarRuntime(string id) {
        return new CarState(id);
    }

    [DELETE("{id}")]//405
    public void DeleteCar(string id)
    {
        //TODO:remove car
    }

    [DELETE("{id}/terminal/{terminalId}")]//work fine
    public void Delete(string id, string terminalId) 
    {
    }

    [PUT("{id}/")]//405
    public void PutCar(string id, CarInfo car)
    {
    }

    [PUT("{id}/terminal/{terminalId}")]//work fine
    public void Put(string id, string terminalID) 
    {
    }
}
Roman Marusyk
  • 19,402
  • 24
  • 55
  • 90
Da Zhang
  • 1
  • 3

0 Answers0