[英]Selfhost REST / ApiController - How to do filterparameters?
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.首先是我不知道很多东西叫什么,因为它是一个“你以前从未这样做过,它需要在昨天完成”-项目。
What works:什么有效:
What i didnt get to work is those ?category=searchterm stuff.我没有开始工作的是那些?category=searchterm的东西。
In the old API https://docs.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.在旧的 API https: //docs.microsoft.com/en-us/aspnet/web-api/overview/older-versions/self-host-a-web-api 中,只需添加类似这个,我不知道如何,但它看起来像反射魔法这应该由 /api/products/?category=category 调用,在我的情况下,在 OWIN 中它没有。
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!感谢您花时间阅读!
Surprise, the answer is damn simple.惊喜,答案很简单。
public IEnumerable<string> Get()
{
// The ApiController has a property for the current request which contains the query string.
var query = this.Request.RequestUri.Query;
return new string[] { "value1", "value2" };
}
Special thanks to @MindSwipe whose link wasn't the answer but got me on the right track.特别感谢@MindSwipe,他的链接不是答案,但让我走上了正确的道路。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.