Basic Syntax
The fields parameter uses the following format:- fields: Comma-separated list of field names to return
Aliases
Thefields parameter has aliases:
fieldsselect
Basic Usage
Single Field
Multiple Fields
Fields are separated by commas (
,) with no spaces.Default Behavior
Without field selection, all fields are returned:Common Use Cases
Minimal Data for Lists
ID and Name for Dropdowns
Excluding Sensitive Fields
Mobile API Responses
Field Selection with Relations
Combine field selection with joins:Main Entity Fields
Thefields parameter controls the main entity fields:
Related Entity Fields
Use the join syntax to select related entity fields:Nested Field Selection
For nested relations, use dot notation in field names:Complete Examples
User Profile API
Blog API
E-commerce API
Combining with Other Parameters
With Filtering
With Sorting
With Pagination
Complete Query
- Filters published posts in Technology category
- Returns only id, title, and excerpt from posts
- Joins author with name and avatar
- Sorts by publish date (newest first)
- Returns 20 posts per page
- Returns first page
Performance Benefits
Reduced Payload Size
Faster Database Queries
Selecting fewer fields can improve database query performance:Reduced Network Transfer
Security Considerations
Protecting Sensitive Fields
Configure which fields can be selected:Field Whitelisting
Entity Configuration
TypeORM Example
Controller Configuration
Frontend Implementation
React Example
JavaScript with RequestQueryBuilder
TypeScript Example
Common Patterns
Dropdown/Select Options
Search Results
Table/Grid Display
Card/Preview Display
Autocomplete
Validation and Errors
Invalid field parameters will be handled according to your configuration:Best Practices
- Always select only needed fields: Don’t default to selecting all fields
- Configure field access: Use
excludeorallowin your controller - Protect sensitive data: Never expose passwords, tokens, or internal fields
- Use TypeScript: Define interfaces for different field selections
- Document available fields: Clearly document which fields are available
- Consider mobile clients: Select minimal fields for mobile endpoints
- Test performance: Measure the impact of field selection on performance
- 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