locked
How to do multiple POST actions on single resource RRS feed

  • Question

  • User-209105085 posted

    I have ASP.NET Web API application. I have resource on which i want to do 3 different operations using POST. So the URL should like this

    http://api.example.com/v1/client/1234/account?sync

    http://api.example.com/v1/client/1234/account?transform

    http://api.example.com/v1/client/1234/account?upload

    1234 is the clientid, All these action methods must be POST. I would like actions like `sync`, `transform` and `upload` to be query string instead of part of the URL ( for example i do not want http://api.example.com/client/1234/account/sync)

    below is my controller ( not working)

    [RoutePrefix("v1")]
    	public class AccountController : ApiController
        {
            private readonly AccountService _service;
    
            public AccountController(AccountService service)
            {
                _service = service;
            } 
    		
    		[HttpPost]
            [Route("client/{clientid:int}/account/{upload}")]
            public async Task Upload([FromUri]int clientid, [FromBody]UploadRequest request)
            {
                //do something here
            }
    
            [HttpPost]
            [Route("client/{clientid:int}/account/{sync}")]
            public async Task<IEnumerable<AccountDTO>> Sync([FromUri]int clientID, [FromBody]IEnumerable<AccountDTO> items)
            {
                //do something here
            }
    
            [HttpPost]
            [Route("client/{clientid:int}/account/{transform}")]
            public async Task<IEnumerable<AccountDTO>> Transform([FromUri]int clientID, [FromBody] IEnumerable<AccountDTO> items)
            {
                //do something here
            }       
        }

    I am getting error `Multiple actions were found that match the request:` 

    How would i structure controller here do i get desired route?

    Wednesday, June 13, 2018 3:31 PM

All replies