Skip to main content

Dynamic querying for APIs

Give your API useful query power without adding another parameter.

Describe the query once, while your API keeps control of what is allowed and executed.

Flexible queries. Deliberate boundaries.

Every new filter should not become a new parameter.

Property-by-property APIs become difficult as query needs grow.

Conventional parameters are familiar and useful for simple endpoints. As query needs expand, every new combination can add another special case, controller branch, or client convention.

The parameter sprawl path

GET /users?
  name=Ann&
  groupName=Staff&
  sortParameter=CreatedAt&
  sortDirection=desc&
  page=1&
  pageSize=25

The endpoint works, but each new query shape tends to add another parameter and another convention.

The structured expression path

(Name contains "Ann" OR Name contains "Ben")
AND GroupName equals "Staff"
AND (Status equals "Active" OR Status equals "Pending")

ServiceQuery® gives the API a structured query model for richer combinations without inventing a parameter for every shape.

Structured request to provider query

Describe the query. Keep authority at the API.

The client sends structured query intent. The API validates and bounds the request. ServiceQuery® builds the corresponding LINQ expression over the queryable source the API already owns.

1

Structured request

Describe filters, sorting, paging, and aggregation as query data.

2

Validated model

Apply the API’s allowed fields, operations, limits, and policy.

3

LINQ expression

Build an expression tree instead of concatenating user-controlled SQL strings.

4

Provider-owned source

Execute through the IQueryable source selected by the API.

5

Bounded result

Return results within the endpoint’s authorization and operational boundaries.

Query power inside an intentional boundary

ServiceQuery® handles query construction. Your API remains in charge.

Safe query construction is one part of a safe API. The server still decides what the client may see, ask for, and execute.

ServiceQuery® provides

  • Structured query representation.
  • Filtering, sorting, paging, and aggregation primitives.
  • LINQ expression-tree construction.
  • Execution through the API’s queryable source.
  • A reduced raw SQL-injection surface by avoiding SQL string construction from query text.

Your API owns

  • Authentication and authorization.
  • Field allowlists and operation policy.
  • Sensitive-field decisions, such as rejecting Salary in a filter.
  • Tenant and ownership scope.
  • Complexity, page-size, rate, classification, and business rules.

See the same intent in code

A small protocol that fits the API you already own.

Follow the request from client intent to server execution, then compare the same model across supported data providers.

Server

app.MapPost("/users/search",
    (ServiceQueryRequest req, AppDb db) =>
{
    var queryable = db.Users.AsQueryable();
    return Results.Ok(req.Execute(queryable));
});

Client

const request = new ServiceQueryRequestBuilder()
    .IsEqual("Status", "Active")
    .SortDesc("CreatedAt")
    .Paging(1, 25)
    .Build();

Use the query model across Entity Framework Core supported databases, Azure Data Tables, CosmosDB, MongoDB, PostGreSQL, or in-memory scenarios where the provider supports the relevant expression.

Inspect. Run. Adopt.

Give your API useful query power without giving up control.

Run a real query, review the security boundary, and decide where a structured query contract belongs in your API.