Serve Builder data across apps
Create a data model in Builder and serve the same data to both Next.js and Flutter applications. Builder data models deliver JSON through the Content API, providing data across multiple platforms and frameworks.
This tutorial shows how to create a Data model to store location data and serve the information across web and mobile apps.
Prerequisites
To get the most out of this tutorial, you need:
- A Builder account and public API key.
- A running Next.js and Flutter apps.
- Basic understanding of REST APIs and JSON.
- Familiarity with Builder Data models and the Data tab.
Final product
The video below shows the entire process of creating a Data model in Builder, creating Content entries, and serving the same data across both Next.js and Flutter apps:
Create and integrate data with Next.js
Step 1: Create a Data model
Create a Data model to store location entries:
- Go to Models and click + Create Model.
- Choose Data from the model type options.
- In the Name field, add a name for the model.
- In the Description field, add a short description of the model.
- Click Create.
Step 2: Add Fields to the Data model
Add fields to structure the location data:
- Go to the Fields tab within your Data model.
- Add a
namefield with type Text. - Click Save.
Repeat the above steps to create additional fields according to the use case and select the relevant Type from the list.
Step 3: Create content entries
Use the new Data model to create Content entries:
- Go to Content and click + New Entry.
- Select your model from the available options.
- Give your entry a descriptive name. For example,
New York. - Fill in the form fields and click Publish.
Repeat the process for as many entries as needed.
Step 4: Integrate Builder in Next.js
Install the Builder React SDK:
Add your API key to .env.local:
Configure Next.js for Builder
To load images from Builder's CDN in your application, configure Next.js to allow images from Builder's domain.
Update your next.config.ts to access Builder images:
Create a route for displaying content
The example below shows how to combine static content with dynamic data from Builder. You fetch model data and make the data available to content entries in the Visual Editor.
Create app/stores/page.tsx:
The example above shows several important concepts:
fetchEntries(): retrieves all content entries from your store-locations data model.fetchOneEntry(): fetches page content from Builder such as layouts and sections.dataprop: passes store data to Builder components, making the data available in the Visual Editor.- Hybrid approach: combines static React components with dynamic Builder content.
For more information, see Data Binding.
Add styling
Create app/stores/stores.module.css:
To run your Next.js application:
Set up Element data bindings
Your store data is now available through the data prop. Bind data to content in the Visual Editor:
- Go to Content in the Builder dashboard.
- Click + New Entry and select the Section model from the dropdown.
- Click the Text block to bind the data.
- In the Data tab, expand Element data bindings, select your store data from the FROM dropdown, and select Text from the GET dropdown.
- The element displays dynamic content from your store's Data model.
The data prop provides dynamic access to your Next.js data in the Visual Editor. The video below demonstrates this data binding workflow:
Fetch Builder data in Flutter
Install Flutter if not already installed, then create a new project. For more information, see the Flutter installation guide.
Step 1: Set up the Flutter project
Create a new Flutter project:
Open the Flutter project in your IDE:
Add the HTTP package to your pubspec.yaml:
Install dependencies:
Step 2: Create API constants and data models
This step sets up the foundation for communicating with Builder's API. Create constants for the API endpoint and models to structure the data your app receives.
Create API constants
These constants centralize your Builder API configuration, making the configuration easy to manage and update your API endpoints.
Create lib/constants/api_constants.dart:
Create data models
These models define the structure of your store location data and handle converting JSON responses from Builder's API into Dart objects that your Flutter app can work with.
Create lib/models/store_location.dart:
Create lib/models/api_response.dart:
Step 3: Create the service and UI components
This step builds the core functionality: a service to fetch data from Builder and UI components to display that data in your app.
Create a service
This service handles the HTTP communication with Builder's Content API, fetching your store location data and handling any network errors that might occur.
Create lib/services/store_service.dart:
Create the UI widget
This reusable widget displays individual store locations in a consistent card format throughout your app.
Create lib/widgets/store_location_card.dart:
Step 4: Create the main screen
The screen uses the service to fetch data from the Builder Data model and displays data using your UI components with loading states and error handling.
Create lib/screens/store_list_screen.dart:
Step 5: Update main.dart
This final step configures your app's entry point to display the store locations screen you just created.
Update your lib/main.dart:
Your Flutter application now displays store location data from the Data model with a native interface. To run your Flutter app:
For iOS:
For Android:
For web:
Make sure you have the appropriate simulators or devices connected before running these commands.
Test the changes
Test how changes in Builder appear across both applications:
- Edit a store location in Builder and click Publish.
- Refresh your Next.js app and Flutter app to see the changes.
Both applications now display the same updated content from your central Builder data source.
What's next
You now have data serving across multiple applications with consistent content delivery. Consider these next steps:
For advanced patterns, see Custom Components and Content Models.