You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The simplest data source we can query is an in-memory .NET collection registered with ctx.MemorySource().
But how the collection is populated remains up to you. The example below shows registering collections from
multiple sources inc. in-line code, populated from a CSV file (utilizing ServiceStack's new
CSV deserialization support) and populated from a 3rd Party API using
HTTP Utils:
//Declaration in codevarcountries=new[]{newCountry{ ...},newCountry{ ...},};//From CSV FileList<Currency>currencies=File.ReadAllText("currencies.csv").FromCsv<List<Currency>>();//From 3rd Party APIList<GithubRepo>repos="https://api.github.com/orgs/ServiceStack/repos".GetJsonFromUrl(req =>req.UserAgent="AutoQuery").FromJson<List<GithubRepo>>();//AutoQuery Data PluginPlugins.Add(newAutoQueryDataFeature{MaxLimit=100}.AddDataSource(ctx =>ctx.MemorySource(countries)).AddDataSource(ctx =>ctx.MemorySource(currencies)).AddDataSource(ctx =>ctx.MemorySource(repos)));
After data sources are registered, you can then create AutoQuery Data Services to query them:
The examples above provides a nice demonstration of querying static memory collections. But Data Sources
offers even more flexibility where you're also able to query and cache dynamic .NET collections that
are customizable per-request.
The registration below shows an example of this where results are dynamically fetched from GitHub's API
and persisted in the local in-memory cache for 5 minutes - throttling the number of requests made
to the external 3rd Party API:
Thanks to the Typed Request DTO we also get an end-to-end Typed API for free which we can use to query
the contributors result-set returned from GitHub's API. As an example we can view the
Top 20 Contributors for the ServiceStack Project with:
vartop20Contributors=client.Get(newQueryContributors{Repo="ServiceStack",OrderByDesc="Contributions",Take=20});top20Contributors.PrintDump();// Pretty print results to Console