Skip to main content
Field selection allows you to specify exactly which fields to return in your API responses. This reduces payload size, improves performance, and gives clients fine-grained control over the data they receive.

Basic Syntax

The fields parameter uses the following format:
  • fields: Comma-separated list of field names to return

Aliases

The fields parameter has aliases:
  • fields
  • select

Basic Usage

Single Field

Multiple Fields

Fields are separated by commas (,) with no spaces.

Default Behavior

Without field selection, all fields are returned:
With field selection:

Common Use Cases

Minimal Data for Lists

Perfect for rendering user lists where you only need basic info.

ID and Name for Dropdowns

Excluding Sensitive Fields

Mobile API Responses

Field Selection with Relations

Combine field selection with joins:

Main Entity Fields

The fields parameter controls the main entity fields:
Returns:
Use the join syntax to select related entity fields:

Nested Field Selection

For nested relations, use dot notation in field names:
Using join syntax is generally more explicit and recommended for selecting related entity fields.

Complete Examples

User Profile API

Blog API

E-commerce API

Combining with Other Parameters

With Filtering

With Sorting

With Pagination

Complete Query

This request:
  1. Filters published posts in Technology category
  2. Returns only id, title, and excerpt from posts
  3. Joins author with name and avatar
  4. Sorts by publish date (newest first)
  5. Returns 20 posts per page
  6. Returns first page

Performance Benefits

Reduced Payload Size

Faster Database Queries

Selecting fewer fields can improve database query performance:

Reduced Network Transfer

Especially important for mobile apps on slow connections.

Security Considerations

Protecting Sensitive Fields

Configure which fields can be selected:

Field Whitelisting

Always use exclude or allow in your CRUD configuration to prevent exposure of sensitive fields like passwords, tokens, or internal IDs.

Entity Configuration

TypeORM Example

Controller Configuration

Frontend Implementation

React Example

JavaScript with RequestQueryBuilder

TypeScript Example

Common Patterns

Search Results

Table/Grid Display

Card/Preview Display

Autocomplete

Validation and Errors

Invalid field parameters will be handled according to your configuration:

Best Practices

  1. Always select only needed fields: Don’t default to selecting all fields
  2. Configure field access: Use exclude or allow in your controller
  3. Protect sensitive data: Never expose passwords, tokens, or internal fields
  4. Use TypeScript: Define interfaces for different field selections
  5. Document available fields: Clearly document which fields are available
  6. Consider mobile clients: Select minimal fields for mobile endpoints
  7. Test performance: Measure the impact of field selection on performance
  8. Use consistent naming: Keep field names consistent across your API

GraphQL-Like Queries

While not as flexible as GraphQL, field selection provides similar benefits:

Advanced Examples

Multi-Level Field Selection

Dynamic Field Selection

Conditional Field Loading

Next Steps

Relations

Select fields from related entities

Filtering

Filter results before selecting fields

Pagination

Paginate through selected fields

Query Parameters

Overview of all query parameters