jeudi 8 février 2018

Specify which fields to return in WebApi Core

I have a WebAPI service where I would like to allow users to specify which fields they'd like returned. For example, say I have the following Person class:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
}

and that calling /api/people/ returns all three fields for all people. How do I handle a request like /api/people?fields=FirstName,Email returning just those two fields for all people? Bonus points if I can map something like first_name to FirstName but that's not required.





Aucun commentaire:

Enregistrer un commentaire