I have a WebApi which exposes a Contact field in my database. Currently it has endpoints for Post (create), Put (edit), Get(return whole list), Get(int id) (return specific field).
So the Get(int id) searches my DB for the contact with that id and returns it in JSON. I would like to implement a method by which the user can submit conditions to my first Get function such as:
GET http://urlformyapi.com/api/apiContact/?querystring
Where the query string might be for example:
firstname=phil
And return all the Phil's.
How is best to make this totally searchable for all of my data fields within contact?
public int contactid { get; set; }
[Required]
public string firstname { get; set; }
[Required]
public string lastname { get; set; }
[Required]
public string email { get; set; }
[Required]
public string mobile { get; set; }
public string company { get; set; }
public string position { get; set;}
public string notes { get; set; }
public string image { get; set; }
I could do an initial get of the whole list and then go through each query parameter like:
//where ContactList begins as the entire list of contacts.
if(notes != null){ ContactList = ContactList.Where(x => x.notes == notes).ToList(); }
Thus refining my list until returning it. But I wondered if there was an easier way which was more robust should my data model change/I want to make more fields searchable.
any thoughts?