AutoQuery

AutoQuery made simple
Instant Query & CRUD APIs

High performance, Industrial strength, effortless, code-first APIs

Rapidly develop rich queryable APIs for

Fast, typed, code-first Queryable APIs

ServiceStack's AutoQuery is a fresh, approach to enable Auto Querying functionality akin to OData's querying support for Web Api, but without its web service anti-patterns, over-architected implementation, large complexity, poor performance, tight-coupling and inhibitive versionability, traits we've strongly recommended against in Why not OData.

Introducing AutoQuery

The solution to overcome most of OData issues is ultimately quite simple: enhance the ideal API the developer would naturally write and complete 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.

AutoQuerying aims to work like optional typing by making it easy to expose contract-less data services for rapid prototyping, then allowing the API to be gradually formalized by decorating Request DTO's with its supported usage, whilst allowing complete freedom in either utilizing and extending AutoQuery's built-in functionality or replacing it entirely without breaking the Service Contract.

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 Services are ServiceStack Services

An important point worthy of highlighting is that AutoQuery Services are just normal ServiceStack Services, utilizing the same Request Pipeline, which can be mapped to any user-defined route, is available in all registered formats and can be consumed from existing typed Service Clients.

In addition to leveraging ServiceStack's existing functionality, maximizing re-use in this way reduces the cognitive overhead required for developers who can re-use their existing knowledge in implementing, customizing, introspecting and consuming ServiceStack services.

AutoQuery RDBMS

Enables the rapid development of high-performance, fully-queryable typed RDBMS data-driven services and supports most major Relational Databases

AutoQuery Data Sources

AutoQuery Data's Open Provider model supports multiple back-end data sources. The 3 data source providers available include:

  • AutoQuery Memory - for querying static or dynamic in-memory .NET collections, some example uses include showing querying a flat-file .csv file and querying a throttled 3rd Party API with it's built-in configurable caching.
  • AutoQuery Service - a step higher than MemorySource where you can decorate the response of existing Services with AutoQuery's rich querying capabilities.
  • AutoQuery DynamoDB - adds rich querying capabilities over an AWS DynamoDB Table, offering a giant leap of productivity than constructing DynamoDB queries manually.

Locode

If you're just getting started AutoQuery we also recommend using the built-in Locode UI which lets you rapidly develop beautiful database-powered Web Apps, from an Instant UI around existing database-first RDBMS tables, or export into highly customizable declarative code-first development model with, on top of AutoQuery's industrial strength APIs to enable a rapid end-to-end typed development model for Web, Mobile & Desktop Apps.

Effortless High performance Query & CRUD APIs

To see the rapid development of AutoQuery in action we've created a quick demo showing how to create a simple multi-user Booking System in minutes from an empty web project, mixed in with the preferred RDBMS, Authentication and Validation.

This step-by-step guide shows how to:

  • Start project from empty web template
  • Add SQLite support
  • Add Authentication support
  • Define code-first database model
  • Define code-first validation
  • Add User Management support
  • Add API event audit history support
  • Use AutoFilters with AutoQuery services
  • Add Excel integration

Create Typed APIs with minimal code

Configure AutoQuery with your RDBMS in your AppHost:

// Configure your database
container.AddSingleton<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
    MapProjectPath("~/northwind.sqlite"), SqliteDialect.Provider));

// Add the AutoQuery Plugin
Plugins.Add(new AutoQueryFeature {
    MaxLimit = 1000
});

Add your custom DTO with route to register a table to query:

[Route("/customers")]
public class QueryCustomers : QueryDb<Customer> {}

That's all that's needed! From your contract-first API blueprint ServiceStack implements a fully queryable, type safe API for the Customer table that you can query with ServiceStack's built-in API Explorer and Locode UIs.

Highly customizable & overridable when needed

Example below shows how to return a custom CustomRockstar Response calling an overridable AutoQuery implementation which services are free to customize as needed:

[Route("/rockstar-albums")]
public class QueryRockstarAlbums
  : QueryDb<Rockstar,CustomRockstar>, IJoin<Rockstar,RockstarAlbum>
{
    public int? Age { get; set; }
    public string RockstarAlbumName { get; set; }
}

// Custom result
public class CustomRockstar
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int? Age { get; set; }

    // Comes from joined table
    public string RockstarAlbumName { get; set; }
}

// Override with custom implementation
public class MyQueryServices : Service
{
    public IAutoQueryDb AutoQuery { get; set; }

    public async Task<object> Any(QueryRockstarAlbums query)
    {
        using var db = AutoQuery.GetDb(query, base.Request);
        var q = AutoQuery.CreateQuery(query, base.Request, db);
        return await AutoQuery.ExecuteAsync(query, q, base.Request, db);
    }
}

Multiple Customization Options

Create APIs for all RDBMS tables with AutoGen

Connect your existing database and configure to use AutoGen to generate typed end to end HTTP services for your database tables:

container.AddSingleton<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
    MapProjectPath("~/northwind.sqlite"), SqliteDialect.Provider));

// Configure AutoQuery to Generate CRUD services
Plugins.Add(new AutoQueryFeature {
    MaxLimit = 1000,
    GenerateCrudServices = new GenerateCrudServices {
        AutoRegister = true
    }
});

AutoGen in Action

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

AutoGen’s code generation is programmatically customizable where the generated types can be easily augmented with additional declarative attributes to inject your App’s conventions into the auto generated Services & Types to apply custom behavior like Authorization & additional validation rules.

After codifying your system conventions the generated classes can optionally be "ejected" where code-first development can continue as normal.

Highly versatile ServiceStack APIs

AutoQuery seamlessly integrates with ServiceStack's endpoints, features and tools for maximum reuse and simplified integrations where it's typed service message contracts are able to drive completely dynamic user interfaces, enabling smart clients to deliver amazing levels of reuse.

Your AutoQuery services can be managed with ServiceStack's built-in dynamic, capability-driven API Explorer and Locode UI's that are enabled by default, integrating with your existing App.

Multiple, clean data formats allows for flexible data 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:

Leverage ServiceStack's ecosystem of features

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.

ServiceStack Plugins use the same interfaces that your custom plugins can use, giving you the ability to extend and expand your service features consistently across AutoQuery or standard ServiceStack services.

Create new App with AutoQuery or AutoGen

AutoQuery Examples

Database-first Example Locode App

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 Logo

Northwind Auto Locode

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

Code-first Example Locode App

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 Logo

Chinook Locode

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

Reuse typed APIs in Optimized UIs

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

Northwind Logo

Talent Blazor Locode

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

More AutoQuery Source Code Examples