AutoQuery

AutoQuery made simple
Instant Query & CRUD APIs

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

Rapidly develop high-performance Queryable & CRUD 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 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.

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:

Easy Excel Data Source Integration

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:

Added Excel Datasource

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.