Your code is going to produce a compile time error because you have 2 methods with same name.
What you should do is, create a 2 seperate methods and use different url patterns for that.
With attribute routing enabled,
[RoutePrefix("api/products")]
public class ProductsController : ApiController
{
public List<string> GetMyDatas(int id)
{
return new List<string> {"product 1", "value2", id.ToString()};
}
[Route("Students/{studId}")]
public List<string> GetStudentDatas(int studid)
{
return new List<string> { "student", "Students", studid.ToString() };
}
}
The first method can be accessed like yourSite/api/products/3
and second one can be accessed like yourSite/api/products/Students/3
where 3 can be replaced with a valid number
Another option is to add a second parameter to your single action method and based on the parameter, determine what data to return.
public List<string> GetMyDatas(int id,string mode="")
{
//based on the mode value, return different data.
return new List<string> {"product 1", "value2", id.ToString()};
}