vendredi 9 août 2019

A decent way to dynamically return partial object in web api response?

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 can 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? everyone has better design ideas?

Aucun commentaire:

Enregistrer un commentaire