1

We have a web api project, which returns objects such as

    public class ChargesInfo
    {
        public string Code { get; set; }
        public decimal? Amc { get; set; }
        public DateTime? AmcDate { get; set; }
        public string AnnualChargeNote { get; set; }
        .....
    }

We would like to allow our customers to return partial data dynamically. For example, they could call this: api/returnFundInfo?fields=amc,amcdate,AnnualChargeNote, we will just return requested fields.

What I think, is that in business logic, we still populate all fields. Then when outputting data, I can use some trick to exclude some fields (possibly ShouldSerialize method from newton Json)

is this sound a good plan? anyone has better design ideas?

daxu
  • 3,514
  • 5
  • 38
  • 76

1 Answers1

1

You can use OData that have out of the box feature $select

api/returnFundInfo?$select=amc,amcdate,AnnualChargeNote

or implement it manually like here

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
  • Hi, This sounds very interesting, but I don't really know enough about Odata, do you mean I don't need to write any code to return individual properties, and it is all done by underlying Microsoft code? – daxu Aug 09 '19 at 16:20
  • It depends. Choose the best way for you. Read more about OData, try to write custom ContractResolver and then you will see what is the better approach – Roman Marusyk Aug 09 '19 at 16:22