Sometimes you may required to return anonymous types from your WebAPI functions; I found a situation like this today, where I need to return list of values with a count, which was using to plot some graphs. Initially I thought of creating an class for this purpose with a count property, but later I found a simple solution using anonymous types.
Here is the code snippet.
This code will work because the CreateResponse() method has an over load which takes T. But sometimes serialization may create some problem.
This is the Get method and you will get a response like this using Fiddler.
Note: It is recommended to use content-type as application/json while requesting to this Get method, when I tried with IE, I found a serialization issue.