Reputation: 4218
I have the following scenario.
There are few Events and each event is represented by group of friends.
1st i request a list of events which is achieved using simple Get request.
http://example.com:6400/api/Events/
Corresponding Rest API : public IEnumerable<Event> Get();
Now i can search the event list and can request for a particular event say (event 5)
http://example.com:6400/api/Events/eventdetail/5.
Corresponding Rest API : public HttpResponseMesssage eventdetail(int id);
But now if i want to receive info about a particular friend(say friend's id is 10) in that event(5) i am unable to find a way. One way i was able to achieve is using a comma separated Get request:
http://example.com:6400/api/Events/eventdetail/5,10.
Corresponding Rest API: Not Sure ????
But i don't think this is the best way to do it. Is there any ways through which i can achieve the desired result and corresponding Rest API.
Upvotes: 0
Views: 1196
Reputation: 25521
Just start accepting two parameters in your method:
public HttpResponseMesssage EventDetail(int id, int friendId) {
//Do your stuff!
}
The corresponding URI would look like:
http://example.com:6400/api/Events/EventDetail/5?friendId=10
Notice how the HTTP parameter name matches the C# method name. For more information about ASP.NET MVC routing I would suggest reading their overview.
Upvotes: 1