Routing with multiple Get methods in ASP.NET Web API

前端 未结 10 787
闹比i
闹比i 2020-11-27 10:13

I am using Web Api with ASP.NET MVC, and I am very new to it. I have gone through some demo on asp.net website and I am trying to do the following.

I have 4 get meth

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 10:57

    Also you will specify route on action for set route

    [HttpGet]
    [Route("api/customers/")]
    public List Get()
    {
       //gets all customer logic
    }
    
    [HttpGet]
    [Route("api/customers/currentMonth")]
    public List GetCustomerByCurrentMonth()
    {
         //gets some customer 
    }
    
    [HttpGet]
    [Route("api/customers/{id}")]
    public Customer GetCustomerById(string id)
    {
      //gets a single customer by specified id
    }
    [HttpGet]
    [Route("api/customers/customerByUsername/{username}")]
    public Customer GetCustomerByUsername(string username)
    {
        //gets customer by its username
    }
    

提交回复
热议问题