2
我正在嘗試製作一個API,它將根據您搜索的內容獲取人員列表 - PhoneNumber,Email,Name如何路由API並使用查詢字符串?
我的問題是我不確定如何路由API來執行此類操作。 ..
[HttpGet, Route("SearchBy/{**searchByType**}/people")]
[NoNullArguments]
[Filterable]
public IHttpActionResult FindPeople([FromUri] string searchByType, object queryValue)
{
var response = new List<SearchSummary>();
switch (searchByType)
{
case "PhoneNumber":
response = peopleFinder.FindPeople((PhoneNumber)queryValue);
break;
case "Email":
response = peopleFinder.FindPeople((Email)queryValue);
break;
case "Name":
response = peopleFinder.FindPeople((Name) queryValue);
break;
}
return Ok(response);
}
難道我創建一個SearchBy
對象,並從一個成員傳遞或可能使用enum
或恆定不知何故?