我有以下情况。
活动很少,每个活动都由一群朋友代表。
首先,我请求使用简单的Get请求即可实现的事件列表。
http://example.com:6400/api/Events/
Corresponding Rest API : public IEnumerable<Event> Get();
现在,我可以搜索事件列表并可以请求特定的事件说(事件5)
http://example.com:6400/api/Events/eventdetail/5.
Corresponding Rest API : public HttpResponseMesssage eventdetail(int id);
但是现在,如果我想在该事件(5)中接收有关特定朋友的信息(例如,朋友的ID为10),则无法找到方法。我能够实现的一种方法是使用逗号分隔的Get请求:
http://example.com:6400/api/Events/eventdetail/5,10.
Corresponding Rest API: Not Sure ????
但是我不认为这是最好的方法。有什么方法可以实现期望的结果和相应的Rest API。
刚开始在您的方法中接受两个参数:
public HttpResponseMesssage EventDetail(int id, int friendId) {
//Do your stuff!
}
相应的URI如下所示:
http://example.com:6400/api/Events/EventDetail/5?friendId=10
注意HTTP参数名称如何与C#方法名称匹配。有关ASP.NET MVC路由的更多信息,建议阅读其概述。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句