I am building a asp.net web api 2 service. I need to create multiple endpoints. The service only returns data. I have around 200 end points & every end point return different type
of data. I do not want to create multiple models representing each type. So instead I have decided to return dynamic
type as the return type of end point.
[Route("abc/xyz")]
public dynamic GetData()
{
List<dynamic> dataList = new List<dynamic>();
dynamic data = new ExpandoObject();
data.category = "Cat 1";
data.value = 210.0;
data.color = "#023867";
dataList.Add(data);
data = new ExpandoObject();
data.category = "Cat 2";
data.value = 110.23;
data.color = "#4094d0";
dataList.Add(data);
data = new ExpandoObject();
data.category = "Cat 3";
data.value = 195.56;
data.color = "#0b4e95";
dataList.Add(data);
return dataList;
}
While this works fine, I have read this is not a good approach. I just want to know what can be disadvantages of this approach?