Quickstarters
Feature Overview
How to Build a Backend for Dart?
25 min
introduction in this tutorial, you’ll learn how to build a backend for dart using back4app we’ll focus on integrating essential back4app features—such as database management, cloud code functions, rest and graphql apis, user authentication, and real time queries (live queries)—into a dart based project since dart is a versatile programming language, you can use it for various backend projects, from simple web servers to full scale applications by leveraging back4app’s intuitive environment, you’ll quickly set up a robust and secure backend framework without heavy server maintenance you’ll see how features like acls, clps, scheduling background tasks, and creating custom logic with cloud code streamline your server side operations after completing this tutorial, you’ll be ready to scale your dart backend or add more advanced integrations prerequisites to complete this tutorial, you will need a back4app account and a new back4app project getting started with back4app https //www back4app com/docs/get started/new parse app if you do not have an account, you can create one for free basic dart development environment you can set this up by installing the dart sdk and any editor of your choice for more information, see get the dart sdk https //dart dev/get dart dart 2 0 or above ensure your environment is up to date, so you can take advantage of recent dart features and package shelf or other server side libraries familiarity with dart and backend concepts if you’re new to dart, review the dart official documentation https //dart dev/guides to build basic fluency make sure you have all of these prerequisites in place before you begin having your back4app project ready and your local dart environment properly configured will help you follow along more easily step 1 – creating a new project on back4app and connecting why create a new back4app project? a new back4app project forms the foundation of your backend, managing your database, security, apis, file storage, and more it gives you an organized structure to build your dart based server side logic creating a back4app project log in to your back4app account click “new app” in the back4app dashboard give your app a descriptive name (e g , “dart backend tutorial”) once created, your project will appear in the back4app dashboard this project is where you’ll configure all backend settings for your dart application install the parse sdk and connect while dart does not have an official parse sdk, there are community maintained libraries like parse server sdk that enable back4app integration you can add it by including the following dependency in your dart project’s pubspec yaml dependencies parse server sdk ^4 0 0 # example version then run dart pub get initialize parse in your dart code (e g , in a main dart file) import 'package\ parse server sdk/parse server sdk dart'; future\<void> main() async { const keyapplicationid = 'your application id'; const keyclientkey = 'your javascript key'; const keyparseserverurl = 'https //parseapi back4app com'; await parse() initialize( keyapplicationid, keyparseserverurl, clientkey keyclientkey, autosendsessionid true, ); // your dart server logic goes here print('parse initialized with back4app!'); } retrieve your application id , javascript key , and parse server url from the back4app dashboard (under “app settings” > “security & keys”) with this step, your dart application can securely interact with your back4app backend framework step 2 – setting up the database creating a data model in the back4app dashboard, navigate to the “database” section and create a new class (e g , “todo”) add columns for your fields, such as title (string) and iscompleted (boolean) creating a data model using the ai agent open the ai agent in your app dashboard describe your desired schema (e g , “please create a todo class with title and iscompleted fields ”) let the ai agent finalize the schema for you reading and writing data using sdk with the parse server sdk library, you can save and query data from your dart code for example import 'package\ parse server sdk/parse server sdk dart'; future\<parseobject?> createtodoitem(string title, bool iscompleted) async { final todo = parseobject('todo') set('title', title) set('iscompleted', iscompleted); final response = await todo save(); if (response success && response result != null) { print('todo created ${response result}'); return response result as parseobject; } else { print('error creating todo ${response error? message}'); return null; } } future\<list\<parseobject>?> fetchtodos() async { final query = querybuilder\<parseobject>(parseobject('todo')); final response = await query query(); if (response success && response results != null) { return response results as list\<parseobject>; } else { print('error fetching todos ${response error? message}'); return null; } } reading and writing data using rest api curl x post \\ h "x parse application id your application id" \\ h "x parse rest api key your rest api key" \\ h "content type application/json" \\ d '{"title" "buy groceries", "iscompleted" false}' \\ https //parseapi back4app com/classes/todo reading and writing data using graphql api mutation { createtodo(input { fields { title "clean the house" iscompleted false } }) { todo { objectid title iscompleted } } } working with live queries (optional) to enable real time updates, turn on live queries in your back4app dashboard (server settings) you can then subscribe from dart, although you may need a specialized library the parse server sdk library may have partial live query support; check its documentation for details step 3 – applying security with acls and clps overview acls (access control lists) restrict read/write at the object level clps (class level permissions) restrict read/write at the class level step by step class level permissions in the back4app dashboard, open the database section, choose a class, and configure clps under “security ” acls in code (using the parse server sdk) future\<parseobject?> createprivatetodo(string title, parseuser owneruser) async { final todo = parseobject('todo') set('title', title); final acl = \<string, dynamic>{}; // grant read/write to the owner acl\[owneruser objectid!] = {"read" true, "write" true}; // disable public read/write acl\[' '] = {"read" false, "write" false}; todo setacl(acl); final response = await todo save(); if (response success && response result != null) { return response result as parseobject; } else { print('error setting acl ${response error? message}'); return null; } } step 4 – writing cloud code functions why cloud code cloud code is essential for creating custom business logic on the server side it saves you from managing your own infrastructure and keeps your code secure and scalable example function and triggers in your main js (for cloud code) // main js parse cloud define('hellodart', (request) => { return `hello from dart and back4app, ${request params name || 'guest'}!`; }); parse cloud beforesave('todo', (request) => { const todo = request object; if (!todo get('title')) { throw 'each todo needs a title!'; } }); deployment using the back4app cli using the dashboard go to cloud code > functions paste your code into main js click deploy npm and cloud code if you need additional npm modules for your cloud code, specify them in your project’s package json this allows you to integrate external apis or advanced operations directly from your server side code step 5 – configuring authentication enable user authentication in the back4app dashboard, you can enable email verification or set up social logins by default, the parse user class stores passwords securely code samples (using parse server sdk in dart) import 'package\ parse server sdk/parse server sdk dart'; future\<void> signupuser(string username, string password, string email) async { final user = parseuser(username, password, email); final response = await user signup(); if (response success) { print('user signed up ${response result}'); } else { print('error ${response error? message}'); } } future\<void> loginuser(string username, string password) async { final user = parseuser(username, password, null); final response = await user login(); if (response success) { print('user logged in ${response result}'); } else { print('error ${response error? message}'); } } social login configure providers like google, apple, or facebook within the back4app dashboard implement the corresponding parse server sdk plugin or a custom oauth flow if available step 6 – handling file storage setting up file storage back4app automatically hosts files you upload via the parse apis you can store images, documents, or any file type example (dart) security considerations you can control who can upload or retrieve files by adjusting your clps or user roles in the back4app dashboard step 7 – email verification and password reset overview email verification confirms that users own the emails they register with, while password reset links provide a secure way to manage lost credentials back4app dashboard configuration go to app settings > email enable verify user emails and password reset customize your email templates as needed implementation when users sign up using a valid email, they receive an email verification link for password resets, call parseuser’s requestpasswordreset method (if available in the parse server sdk) or the rest endpoint step 8 – scheduling tasks with cloud jobs what cloud jobs do cloud jobs let you schedule tasks at set intervals, like cleaning old records or sending periodic reports they operate in the background, independent of user triggered actions example in main js , add parse cloud job('cleanupoldtodos', async (request) => { const todo = parse object extend('todo'); const query = new parse query(todo); const now = new date(); const thirty days = 30 24 60 60 1000; const cutoff = new date(now thirty days); query lessthan('createdat', cutoff); try { const oldtodos = await query find({ usemasterkey true }); await parse object destroyall(oldtodos, { usemasterkey true }); return `deleted ${oldtodos length} old todos `; } catch (err) { throw new error('error during cleanup ' + err message); } }); scheduling go to app settings > server settings > background jobs schedule cleanupoldtodos to run daily or at an interval you choose step 9 – integrating webhooks definition webhooks let your back4app app make http requests to an external service on certain events this is helpful for integrating with third party services like slack or stripe configuration go to more > webhooks in your back4app dashboard click add webhook and provide an endpoint (e g , https //your external service com/webhook endpoint ) specify the trigger event (e g , after a todo is created) example if you have a slack webhook url, you can configure it to receive a notification whenever a new todo is inserted this seamless connection between your dart backend and external tools boosts automation step 10 – exploring the back4app admin panel where to find it in your back4app console, open more > admin app and enable the panel features manage database records easily review logs, background jobs, and analytics control user access and roles conclusion by following these steps, you have built a secure backend for dart on back4app managed your database through parse classes and fields created custom cloud code to handle server side logic secured data using acls, clps, and user authentication scheduled background tasks with cloud jobs integrated external services using webhooks explored the admin panel for easy data management this solid foundation prepares you to deploy dart projects efficiently, whether you’re building full scale web servers, microservices, or specialized applications from here, you can scale up your backend framework, add more complex logic, or integrate advanced features such as push notifications or advanced analytics next steps explore production readiness use caching strategies, handle concurrency, and optimize performance for high traffic integrate advanced features such as role based access control, more social logins, or real time collaboration tools check out official back4app docs for deeper insights into logs, security, and performance tuning experiment with additional packages like package shelf to create custom web servers alongside your parse based data layer, leveraging dart’s capabilities as a flexible programming language with this knowledge of how to build a backend for dart , you have a powerful way to handle data, secure your server side processes, and automate your app’s workflows—all without the need for significant infrastructure overhead