Connect to a REST API
FDC Pro separates the dataset contract from the HTTP client. FdcJsonAdapter defines the canonical data envelope, while FdcRestAdapter models REST requests and lets the application choose the transport implementation.
1. Create the adapter
final adapter = FdcRestAdapter(
source: 'customers',
baseUri: Uri.parse('https://api.example.com/data'),
onSend: sendRequest,
);
onSend receives an FdcRestRequest. Implement it with the HTTP package, Dio, a generated client, interceptors, authentication middleware, or a test fake.
2. Create the dataset
final customers = FdcDataSet(
fields: const [
FdcIntegerField(name: 'customer_id', isKey: true),
FdcStringField(name: 'company', size: 120),
FdcStringField(name: 'city', size: 80),
],
adapter: adapter,
paging: const FdcDataPagingOptions(
enabled: true,
mode: FdcDataPagingMode.standard,
pageSize: 100,
),
);
3. Open normally
await customers.open();
Filtering, sorting, search, paging, apply operations, and aggregates use the adapter contract according to configured capabilities and callbacks.
Backend response shape
A successful open response follows the canonical envelope:
{
"source": "customers",
"rows": [
{
"customer_id": 1,
"company": "Northstar Trading",
"city": "Boston"
}
],
"totalCount": 1
}
Keep transport concerns outside the dataset
Authentication headers, retries, request tracing, endpoint policy, and HTTP client selection belong in the transport layer. The dataset should remain focused on fields, records, query state, editing, validation, and change tracking.
See JSON and REST Adapters and Server-Side Operations.