user2688063
user2688063

Reputation: 313

Web API GET method with 2 parameters

I have a GET method that requires 2 parameters, my implementation is below. But I am getting an error. Is it the right way? At first I thought I can only pass one param, after I build the code I did not see an error, but when I consume the method in fiddler I am getting an error.

Suggestions please.

public class ProfessionalController : ApiController
{
    public IProfessionalRepository professionalRepository;

    public ListProfessionalController(IProfessionalRepository repo)
    {
        professionalRepository = repo;
    }

    [HttpGet]

    public List<Professional> GetProfessionals(int companyId, string professionalName)
    {
        return professionalRepository.GetProfessionals(companyId, professionalName);
    }

}

Upvotes: 0

Views: 71

Answers (1)

Yishai Galatzer
Yishai Galatzer

Reputation: 8862

You need to call with a URI like: /api/Professional?companyId=10&professionalName=Prof.

The [HttpGet] is not necessary because GetProfessionals is already [HttpGet] by convention

Upvotes: 1

Related Questions