Customer service request is the best approach to implement a search

What would you guys recommend as the best way to implement a search in servicestack. For example, at the moment I have an advanced search form, which in the backend simply dynamically creates a linq request. If I wanted to set the search function using the service stack, this is the best way to do this.

I saw some people use the idea of ​​creating a query property, for example [object] .FirstnameStartsWith, [object] .SurnameContains, etc.

+4
source share
2 answers

I went with something like this

[Route("/things", "GET")] public class ThingList { public string Term { get; set; } public int Take { get; set; } public int Skip { get; set; } } public partial class ThingService : Service { public object Get(ThingList req) { var query = this.Things // from somewhere if(!string.IsNullOrEmpty(req.Term)) query = query.Where(x => x.Name.Contains(req.Term)); if(req.Skip > 0) query = query.Skip(req.Skip); if(req.Take > 0) query = query.Take(req.Take); return query.ToList(); } } 
+1
source

There is no best way design for developing APIs for services, but your goals should be as clear and user-friendly as possible so that customers can pinpoint what the service is doing just by looking at the DTO request.

As a rule, services should be cohesive and relevant to use the context of the client context consuming them, for example, adding a new field / function for this request should potentially be useful for existing customers who already use this service.

Finding and filtering a result set is a good example of this, where each added field / function filters the target result set.

Other problems that arise when developing services are the ability to cache, that is, I separate the long-term results of caching from the short-term information that is not related to caching.

0
source

All Articles