ServiceStack's AutoQuery is a fresh, approach to enable Auto Querying functionality akin to OData's querying support for Web Api,
but without its webservice anti-patterns
where instead of adopting an opaque implementation encumbered syntax, it adheres to HTTP API's simple flat structure by instead
enhancing the ideal API the developer would naturally write and completes their implementation for them!
This is the design philosophy behind AutoQuery which utilizes conventions to automate creation of intent-based self-descriptive APIs
that are able to specify configurable conventions and leverage extensibility options to maximize the utility of AutoQuery services.
Great alternative to OData, GraphQL or JSON:API
Connect to anything with data
Expose data from various data sources including
RDBMS,
In Memory,
DynamoDb
or even
other services
through consistent flexible APIs where clients can control the query details.
Works with your favorite databases
AutoQuery RDBMS
works with anything OrmLite can connect to, including:
PostgreSQL
SQL Server
SQLite
MySQL
MariaDB
AWS Aurora
Clean REST routes, accessible from everywhere
Unlike OData and GraphQL, AutoQuery provides clean REST services making them easy to use from standard browsers, avoiding the requirement for complex clients.
Unmatched client integration experience
Add ServiceStack Reference provides best in class client generation in a multitude of languages straight from the server you're integrating with.
Instant Client Apps can generate working native client solutions through an easy to use free web tool, only needing a base URL of a ServiceStack service.
AutoQuery
AutoQuery utilizes conventions to automate the creation of highly productive, intent-based self-descriptive APIs
In this video, we demonstrate how to use AutoQuery to turn a static XKCD comic dataset from Hugging Face into a Web API,
addressing common issues of siloed data.
By creating well-defined AutoQuery APIs, we make the data more accessible and enable efficient data integrations
for rapid creation of production Web Apps which we demonstrate in new lightweight a Razor SSG Vue App.
ServiceStack Locode App is a generated API driven by your service metadata. When combined with AutoQuery,
it becomes a way to rapidly develop web applications with robust service APIs that can be later extended with custom UIs.
In this video we show 3 examples from generating everything from an existing database, making customizations to the Locode
App, and finally reusing all your services in a custom Blazor WASM App
Getting Started
Create APIs with minimal code-first DTOs
AutoQuery can be enabled in any ServiceStack project with a few easy steps:
1. Configure your preferred database
Configure your .NET App with the
OrmLite NuGet package
of the RDBMS you want to use. SQLite is a great option to evaluate AutoQuery without any external dependencies:
Configure your App to use your database. We recommend using a
Modular Startup
configuration for the greater encapsulation and flexibility.
In this example we'll create a simple Todo table:
// Configure.Db.cs
using ServiceStack.Data;
using ServiceStack.OrmLite;
using ServiceStack.DataAnnotations;
[assembly: HostingStartup(typeof(MyApp.ConfigureDb))]
namespace MyApp;
public class Todo
{
[AutoIncrement]
public long Id { get; set; }
public string Text { get; set; }
public bool IsFinished { get; set; }
}
public class ConfigureDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services =>
services.AddSingleton<IDbConnectionFactory>(
new OrmLiteConnectionFactory("db.sqlite", SqliteDialect.Provider)));
.ConfigureAppHost(appHost => {
// Create and populate Todo Table if it doesn't exist:
using var db = appHost.Resolve<IDbConnectionFactory>().Open();
if (db.CreateTableIfNotExists<Todo>())
{
db.Insert(new Todo { Text = "Learn" });
db.Insert(new Todo { Text = "AutoQuery" });
}
});
}
2. Configure AutoQuery
AutoQuery can then be enabled by registering the AutoQueryFeature plugin:
// Configure.AutoQuery.cs
using ServiceStack;
[assembly: HostingStartup(typeof(MyApp.ConfigureAutoQuery))]
namespace MyApp;
public class ConfigureAutoQuery : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost => {
appHost.Plugins.Add(new AutoQueryFeature {
MaxLimit = 1000,
//IncludeTotal = true,
});
});
}
3. Create AutoQuery APIs
With AutoQuery configured, we can now start creating AutoQuery APIs, a minimal working example
is an empty Request DTO which we'll make available via the /todos route:
// ServiceModel/Todos.cs
using ServiceStack;
namespace MyApp.ServiceModel;
[Route("/todos")]
public class QueryTodos : QueryDb<Todo> {}
4. Query your API
That's all that's needed! From your contract-first API blueprint ServiceStack implements a fully queryable,
type safe API for the Todo table that you can immediately viewing the API from the /todos
route in a browser where you can immediately benefit from the
Auto HTML API page:
With links to view the API response in available formats and the API details
API Explorer:
Hopefully this simple example shows how easy it is to get up & running and become
immediately productive with AutoQuery. For larger projects we recommend adopting the
physical project structure
and creating RDBMS tables with OrmLite's
Code-First DB Migrations.
In this video we show a step by step process for start with an existing database and customizations without the need for code first models.
Locode is a generated API driven by your APIs metadata.
Combined with other high-level ServiceStack features, it becomes a way to rapidly develop web applications with robust service APIs
that can be later extended with custom UIs.
ServiceStack’s AutoGen enables a number of exciting possibilities, predominantly it’s the fastest way to ServiceStack-ify an existing systems
RDBMS where it will serve as an invaluable tool for anyone wanting to quickly migrate to ServiceStack and access its functionality
ecosystem around ServiceStack Services
Highly versatile ServiceStack APIs
Simple to create, fast to run, effortless to consume & amazingly productive
AutoQuery seamlessly integrates with ServiceStack's endpoints, features and tools for maximum reuse and simplified integrations
where it's typed service message contracts and rich metadata are able to drive completely dynamic, capability-driven
user interfaces like
API Explorer and
Locode
whilst .NET Apps built using the
ServiceStack.Blazor's
and
Vue's AutoQueryGrid & AutoForm
componnets, enabling amazing levels of reuse.
Multiple, clean data formats allows for flexible integrations
As all AutoQuery Services are pure HTTP APIs available in multiple data formats they allow for simple,
rich integrations like being able to use its CSV Format to create live table data sources in Excel or easily import
any query into any data store supporting
CSV imports:
AutoQuery's usage of simple, user-defined Clean URLs and intuitive implicit query conventions makes
it easy for stakeholders to create custom Queries of their Systems Data that they can link to directly
in their Excel worksheets to generate Live Reports:
AutoQuery services are ServiceStack services, so they benefit from the ServiceStack ecosystem of features.
This makes responding to changing requirements more straight forward as all these features are designed from the ground up to
work together with clean consistent APIs.
To demonstrate a database-first development workflow we've enabled
AutoGen on the Northwind
sample database to generate
AutoQuery &
CRUD
APIs whose capabilities are used to power the custom Northwind Locode App
Northwind Auto is a customized database-first Northwind App using
AutoGen to generate
AutoQuery &
CRUD APIs
in less than 120 Lines of Code in
Configure.AppHost.cs
For greater customizability we've exported AutoGen APIs of the Chinook sample database into typed AutoQuery APIs & Data Models to unlock more flexible code-first declarative & programmatic dev models that includes Custom UI components to showcase potential enhancements in Locode Apps
Chinook is a customized Code-First App using
AutoGen to
export
Chinook's RDBMS Tables into
Models.cs
generating code-first
AutoQuery APIs
& Data Models that's further annotated to create a customized Locode App
AutoQuery's declarative dev model lets you focus on your new App's business requirements where its data model,
API capabilities, input validation & multi-user Auth restrictions can be defined simply using annotated C# POCOs.
This provides immense value at the start of the development cycle where functional prototypes can be quickly iterated to
gather business requirements
Once requirements have been solidified, the typed AutoQuery APIs can easily be reused to develop custom UIs to optimize
important workflows.
Talent Blazor is a new App showcasing
an example of this where its entire back-office functionality can be managed through Locode whilst an optimized Blazor WASM
App is created to optimize its unique workflow requirements which also benefits from the superior productive dev model
of its Typed APIs
Talent Blazor is a Blazor WASM App built around a HR's unique workflow for processing Job Applications
from initial Application, through to Phone Screening and Interviews by multiple employees, capturing
relevant feedback at each application event, with successful Applicants awarded the Job
It's co-developed & deployed with a customized Locode App that manages all other CRUD Database Access
AutoQuery enables a highly productive platform capable of rapidly developing a majority of App's CRUD functionality
to enable a hybrid development model which can benefit from using customized
AutoQueryGrid components
to effortlessly implement the CRUD functionality to manage the Back office supporting tables,
freeing up developers to focus a majority of their efforts where they
add the most value - in the optimized customer-facing UI.
Blazor Diffusion
We’ve created
blazordiffusion.com
to best illustrate this potential
- a new ServiceStack Blazor Tailwind App for
Stable Diffusion - a deep learning text-to-image model
that can generate quality images from a text prompt. It’s a great example of Hybrid Development where its entire user-facing UI
is a bespoke Blazor App optimized for creating and discovering Stable Diffusion generated images, whilst all its
supporting admin tasks
to manage the back office tables that power the UI were effortlessly implemented with custom AutoQueryGrid components.