From Microsoft's CRUD tutorial for their Web API:
Finally, add a method to find products by category:
public IEnumerable<Product> GetProductsByCategory(string category)
{
return repository.GetAll().Where(
p => string.Equals(p.Category, category, StringComparison.OrdinalIgnoreCase));
}
If the request URI has a query string, Web API tries to match the query parameters to parameters on the controller method. Therefore, a URI of the form "api/products?category=category" will map to this method.
Is there any way to make this generic? As in GetProductsByWhateverIsInTheURI(string WhateverIsInTheURI) or "api/products?whatever=whatever"?
Thank you.
GetProductsByWhateverIsInTheURI??category=_category_as a query string in the URI. This is mapped to `GetProductsByCategory(string category) because the name of the parameter matches the one queried for in the URI. I was trying to figure out if there's a way to accept any sort of parameter in one generic method.