Reputation: 2517
Doing my first steps with ASP.NET Web API I am trying to develop an api that handles forum posts.
In the PostsController
I have the following method, that I can invoke using 'localhost/api/posts':
public IEnumerable<__PostModel> GetPosts()
Now I have also this method, which I invoke using: 'localohost/api/posts/5':
public string GetPosts(int id)
Now I need another method which returns a range of posts:
public IEnumerable<__PostModel> GetRange(int from, int to)
I can't figure out how to call it. I'm trying 'localohost/api/posts?from=5&to=8' and it always call the GetPosts() method. What am I missing here?
Upvotes: 0
Views: 197
Reputation: 21713
Your method is called GetRange
and your URL's endpoint is posts
. It won't find it. Renaming the method to GetPosts
(thus creating a third overload) should work.
public IEnumerable<__PostModel> GetPosts(int from, int to)
Upvotes: 2