Overview
The API configuration controls how the MTB Backend REST API behaves, including pagination limits and response formatting. Configuration is defined inconfig/api.ts.
REST API Settings
The REST API configuration controls default behavior for all API endpoints.Pagination
The default number of items returned per page when no limit is specified in the request.
The maximum number of items that can be requested in a single page. Requests exceeding this limit will be capped at this value.
Whether to include total count metadata in paginated responses. When enabled, responses include the total number of available records.
Configuration Details
Default Limit
ThedefaultLimit setting controls how many records are returned when a client doesn’t specify a limit:
Using a reasonable default limit prevents accidentally returning large datasets and helps maintain API performance.
Maximum Limit
ThemaxLimit setting prevents clients from requesting excessive amounts of data:
With Count
ThewithCount setting determines whether pagination metadata includes the total count:
Disabling
withCount can improve performance for large datasets where counting total records is expensive. However, clients won’t know the total number of pages available.Configuration Example
Using Pagination in Requests
Clients can control pagination using query parameters:Basic Pagination
Pagination Parameters
The page number to retrieve (1-indexed)
The number of items per page (capped at
maxLimit)Alternative to
page: the index of the first item to return (0-indexed)Alternative to
pageSize: the number of items to returnResponse Format
Paginated responses follow a consistent structure:Best Practices
Choosing Default Limit
- Small datasets: 25-50 items per page
- Medium datasets: 10-25 items per page
- Large datasets: 5-10 items per page
- API responses: Consider mobile data usage and response time
Choosing Maximum Limit
- Public APIs: 100-250 items (prevents abuse)
- Internal APIs: 500-1000 items (trusted clients)
- Bulk operations: Consider dedicated export endpoints instead of high limits
Performance Considerations
Common Use Cases
Mobile Applications
Admin Dashboards
Data Export Features
For true bulk exports, consider implementing dedicated export endpoints with streaming or background job processing instead of relying on high pagination limits.
Troubleshooting
Slow API Responses
If your API is slow:- Reduce default and max limits
- Disable
withCountfor large tables - Add database indexes on frequently queried fields
- Consider implementing cursor-based pagination for very large datasets
Client Receiving Fewer Items Than Requested
The API enforcesmaxLimit:
