I got multiple problems. The first is that i dont know what many things are called because its a "you never did this before and it needs to be done yesterday"-project.
- I need to create a REST service as part of a winforms application. It needs to return json. No html and no other webstuff, so i dont need the ASP.Net/Core overhead.
- I decided on OWIN selfhost because the Self-Host ASP.NET Web API is tagged as "old, use owin instead", so i did that.
- It is not ASP MVC
What works:
- I got that thing running according to https://learn.microsoft.com/en-us/aspnet/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api and the get/post etc. commands all work.
- I found questions on SO that showed me how to return result codes and json constructs, nice!
What i didnt get to work is those ?category=searchterm stuff.
In the old API https://learn.microsoft.com/en-us/aspnet/web-api/overview/older-versions/self-host-a-web-api it is shown to work by just adding a method like this and i don't know how but it looks like by reflection magic this should be called by /api/products/?category=category which in my case, in OWIN it does not.
public IEnumerable<Product> GetProductsByCategory(string category)
{
return products.Where(p => string.Equals(p.Category, category,StringComparison.OrdinalIgnoreCase));
}
I'm not sure what i should do. The documentation doesn't show anything on how to enable it. Depending on where i looks, its called "query" or "filter", but searching that leads to a lot of stuff that is not related. What is that even called?
Thanks for taking the time to read!