Quickstarters
CRUD Samples
How to Develop a Basic CRUD Mobile App with NativeScript?
28 min
overview in this guide, you'll create a full featured crud (create, read, update, delete) mobile application using nativescript this tutorial walks you through setting up your project, configuring a robust backend on back4app, and integrating a nativescript frontend to manage and update data seamlessly we begin by establishing a new back4app project called basic crud app ns , which serves as the backbone for your data operations you’ll then define a flexible database schema by setting up collections and fields, either manually or by leveraging the back4app ai agent following this, you'll utilize the back4app admin app—a no code interface designed for effortless data manipulation—to perform crud tasks efficiently lastly, you will integrate your nativescript mobile app with back4app using rest apis, ensuring your backend is secure with advanced access controls by the end of this tutorial, you'll have a production ready mobile application that not only performs essential crud operations but also incorporates user authentication and secure data handling main insights master the art of building crud mobile apps that manage data efficiently using a reliable backend learn how to design a scalable database and seamlessly integrate it with a nativescript frontend discover how to use a drag and drop admin interface (the back4app admin app) to simplify data management understand best practices for securing your backend with acls and class level permissions prerequisites a back4app account with a new project set up if you need assistance, check out getting started with back4app https //www back4app com/docs/get started/new parse app a nativescript development environment install the nativescript cli and set up your environment by following the nativescript documentation https //docs nativescript org/start/quick setup basic knowledge of javascript/typescript, nativescript, and restful apis familiarize yourself with the nativescript guides https //docs nativescript org/ if necessary before starting, ensure you have step 1 – project initialization establishing a new back4app project log into your back4app dashboard select the “new app” option name your project basic crud app ns and follow the instructions to create it create new project once your project is set up, it will be listed in your dashboard, ready for backend configuration and management step 2 – designing the database schema crafting your data model for this crud mobile app, you'll create key collections below are sample collections along with the essential fields and data types to set up your schema, enabling the fundamental operations to create, read, update, and delete data 1\ items collection this collection holds details for each item field data type description id objectid auto generated primary identifier title string name or title of the item description string short summary of the item created at date timestamp when the item was created updated at date timestamp when the item was last modified 2\ users collection this collection stores user credentials and details field data type description id objectid auto generated primary identifier username string unique username of the user email string unique email address password hash string securely hashed password created at date account creation timestamp updated at date last update timestamp for the user profile you can create these collections manually in the back4app dashboard by adding a new class for each collection and defining the respective columns create new class define each field by selecting a data type, naming it, and specifying default values or requirements create column utilizing the back4app ai agent for schema setup the back4app ai agent is an efficient tool within your dashboard that can auto generate your database schema based on a prompt describing your desired collections and fields this feature streamlines the process and ensures consistency how to leverage the ai agent launch the ai agent access it from the back4app dashboard or project settings detail your data model input a prompt outlining the collections and fields you require review and confirm examine the generated schema suggestions and apply them to your project sample prompt create these collections for my back4app project 1\) collection items \ fields \ id objectid (auto generated) \ title string \ description string \ created at date (auto generated) \ updated at date (auto updated) 2\) collection users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ password hash string \ created at date (auto generated) \ updated at date (auto updated) this process saves time and ensures your schema is both consistent and optimized step 3 – activating the admin app & performing crud operations introducing the admin app the back4app admin app offers a no code interface to manage your backend data easily its drag and drop design enables quick and effective crud operations how to enable the admin app go to the “more” menu in your back4app dashboard select “admin app” and then click “enable admin app ” set up your admin credentials by creating the first admin user, which also establishes roles (e g , b4aadminuser ) and system collections enable admin app once enabled, log into the admin app to begin managing your collections admin app dashboard executing crud operations with the admin app within the admin app, you can create records use the “add record” option within any collection (for example, items) to insert new entries read/modify records click on any record to view its details or edit its information remove records select the delete option to eliminate records that are no longer needed this intuitive tool enhances user experience by simplifying data management tasks step 4 – connecting nativescript with back4app after setting up your backend and managing data via the admin app, the next step is to link your nativescript mobile app to back4app using rest apis for integration since the sdk integration may not be optimal for nativescript in this scenario, you can utilize rest apis to perform crud operations example fetching data with rest below is an example of how to retrieve items from your back4app database using a rest call in a nativescript service file // app/services/item service ts import { http } from '@nativescript/core'; const application id = 'your application id'; const rest api key = 'your rest api key'; export async function fetchitems() { try { const response = await http request({ url 'https //parseapi back4app com/classes/items', method 'get', headers { 'x parse application id' application id, 'x parse rest api key' rest api key } }); const data = response content tojson(); return data results; } catch (error) { console error('error fetching items ', error); throw error; } } integrate similar rest api calls within your nativescript components to handle create, update, and delete operations step 5 – securing your backend implementing access control lists (acls) protect your data by setting acls for each object for example, to create a private item, use the following approach // app/services/item service ts import { http } from '@nativescript/core'; const application id = 'your application id'; const rest api key = 'your rest api key'; export async function createprivateitem(itemdata { title string; description string }, ownerid string) { const payload = { title itemdata title, description itemdata description, acl { \[ownerid] { read true, write true }, " " { read false, write false } } }; try { const response = await http request({ url 'https //parseapi back4app com/classes/items', method 'post', headers { 'x parse application id' application id, 'x parse rest api key' rest api key, 'content type' 'application/json' }, content json stringify(payload) }); return response content tojson(); } catch (error) { console error('error creating item ', error); throw error; } } configuring class level permissions (clps) within the back4app dashboard, adjust the clps for each collection to define default access rights this helps ensure that only authorized users can access or modify sensitive data step 6 – user authentication setting up account management back4app utilizes parse’s user class to manage authentication in your nativescript app, implement registration and login processes as demonstrated below example user registration // app/services/auth service ts import { http } from '@nativescript/core'; const application id = 'your application id'; const rest api key = 'your rest api key'; export async function signup(username string, password string, email string) { const payload = { username, password, email }; try { const response = await http request({ url 'https //parseapi back4app com/users', method 'post', headers { 'x parse application id' application id, 'x parse rest api key' rest api key, 'content type' 'application/json' }, content json stringify(payload) }); return response content tojson(); } catch (error) { console error('sign up error ', error); throw error; } } a similar method can be used for logging in and managing user sessions additional functionalities like social logins, email confirmations, and password resets can be configured through the back4app dashboard step 7 – conclusion and future directions well done! you have now created a complete basic crud mobile application using nativescript and back4app your project, basic crud app ns , includes a well defined backend with collections for items and users, managed seamlessly via the admin app you have also integrated your nativescript frontend with back4app through rest apis and secured your data with robust acls and clps next steps enhance your mobile app add features such as detailed views, search functionality, and push notifications expand functionality integrate advanced backend features like cloud functions or third party api services further learning explore the back4app documentation https //www back4app com/docs and additional nativescript resources to refine your skills happy coding and best of luck with your future mobile app projects!