Skip to main content

Integration examples

Useful queries inside deliberate API boundaries.

See how ServiceQuery® fits inside real endpoints with server-owned scope, field policy, operational limits, observability, and tenant isolation.

Flexible queries. Deliberate boundaries.

A bounded integration path

Put query power inside the boundary you already operate.

A useful endpoint separates client intent from server authority and provider execution.

1

Establish scope

Authenticate the caller and apply ownership, tenant, lifecycle, or other server-owned filters.

2

Check the request

Allow only the fields and operations that make sense for this endpoint.

3

Bound the work

Set page-size, complexity, sort, rate, and business limits before execution.

4

Execute the query

Run the request over the queryable source selected by the API.

5

Observe the path

Record useful normalized query information without treating raw client input as trusted evidence.

Scope before query

The client query operates inside server-owned scope.

Dynamic querying does not replace authorization or tenant isolation. Establish the base query first, then execute the client request against that scoped source.

Ownership and lifecycle

var baseQuery = db.Orders
    .Where(order => order.UserId == userId)
    .Where(order => !order.IsDeleted);

return Results.Ok(request.Execute(baseQuery));

Tenant isolation

var baseQuery = db.Items
    .Where(item => item.TenantId == tenantId);

return Results.Ok(request.Execute(baseQuery));

Define the query surface

Expose the fields and operations your endpoint can support.

A structured request is not permission by itself. Use an API-owned policy to reject fields and operations that do not belong on the endpoint.

Allow the intended fields

var allowedFields = new HashSet<string>
{
    "Name",
    "Status",
    "CreatedAt"
};

var requested = request.Filters
    .SelectMany(filter => filter.Properties ?? Enumerable.Empty<string>())
    .Distinct(StringComparer.OrdinalIgnoreCase);
var disallowed = requested
    .Except(allowedFields, StringComparer.OrdinalIgnoreCase);
if (disallowed.Any()) return BadRequest();

Keep policy with the API

  • Reject sensitive fields such as Salary when the endpoint policy does not allow them.
  • Allow only the operations appropriate for the resource and client.
  • Keep authentication, authorization, and data classification outside the query builder.

ServiceQuery provides the structured query path. The API remains the authority over the exposed data contract.

Bound the work

Useful query power still needs operational limits.

Page size, filter depth, sort count, rate limits, and business rules help keep a flexible endpoint predictable to operate.

Limit the result size

var pageSizeFilter = request.Filters.FirstOrDefault(filter =>
    string.Equals(filter.FilterType, "pagesize", StringComparison.OrdinalIgnoreCase) ||
    string.Equals(filter.FilterType, "ps", StringComparison.OrdinalIgnoreCase));

if (pageSizeFilter is not null &&
    (!int.TryParse(pageSizeFilter.Values.FirstOrDefault(), out var pageSize) || pageSize > 100))
{
    return Results.BadRequest("Page size cannot exceed 100");
}

Choose the limits deliberately

  • Set a maximum page size.
  • Cap filter depth and sort count.
  • Apply rate and complexity limits appropriate to the endpoint.
  • Keep provider and business rules visible in the API implementation.

Observe the normalized request

Log the structure you need to understand the endpoint.

Useful observability describes fields, operators, and limits without treating raw client text as trusted or necessary log content.

Record query shape

var fields = request.Filters
    .SelectMany(filter => filter.Properties ?? Enumerable.Empty<string>())
    .Distinct(StringComparer.OrdinalIgnoreCase)
    .ToArray();

logger.LogInformation(
    "Query: Fields={Fields}, Filters={FilterCount}",
    fields,
    request.Filters.Count);

What this helps reveal

  • Which fields clients are asking to use.
  • How much filter composition an endpoint receives.
  • Whether page-size and complexity policies are being exercised.
  • Where provider or endpoint behavior needs a closer review.

A complete bounded endpoint

Keep the recipe visible from request to result.

The implementation is small. The important part is preserving the order of authority, policy, execution, and observation around it.

Client intent

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

Server-owned execution

var scopedQuery = db.Products
    .Where(product => product.TenantId == tenantId)
    .Where(product => !product.IsDeleted);

return Results.Ok(request.Execute(scopedQuery));

Inspect. Run. Adopt.

Make the boundary part of the query design.

Start with the request model, review the security boundary, and apply the integration pattern to an API you control.