Quickstarters
CRUD Samples
Building a Basic CRUD Application with Polymer: A Comprehensive Walkthrough
41 min
overview in this guide, you'll learn how to develop a fully functional crud (create, read, update, delete) application using polymer this walkthrough demonstrates how to perform essential operations for managing and modifying data you’ll begin by setting up a back4app project, titled basic crud app polymer , which will serve as the backend for your application following this, you will craft a scalable data model by outlining precise collections and fields—either manually or with the assistance of the back4app ai agent—to ensure your database is optimized for crud operations next, you’ll leverage the back4app admin app, a user friendly drag and drop management interface, to streamline your data operations finally, you will integrate your polymer frontend with back4app using rest/graphql apis while reinforcing backend security with sophisticated access controls by the end of this tutorial, you will have constructed a production ready web application that supports core crud operations and includes user authentication and robust data management features what you will learn develop a crud application that efficiently manages data with a reliable backend design a scalable backend and connect it with a polymer based frontend utilize a drag and drop admin interface (back4app admin app) to facilitate data operations deploy your application using modern techniques including containerization with docker prerequisites before starting, ensure you have a back4app account with an active project for assistance, check out getting started with back4app https //www back4app com/docs/get started/new parse app a polymer development setup use polymer cli or similar tools and verify that node js (v14 or later) is installed a basic grasp of javascript, polymer, and rest apis you can refer to the polymer documentation https //www polymer library polymer project org/3 0/docs/devguide/feature overview for more details step 1 – setting up your project initiating a new back4app project access your back4app account select the “new app” option from your dashboard assign the project name basic crud app polymer and follow the instructions to finalize project creation create new project after completing these steps, your project will be visible on the back4app dashboard, forming the backbone for your backend configuration step 2 – crafting your database schema structuring your data model for this crud app, several collections are needed below are example collections along with fields and their respective types, which will help you design a robust database schema capable of handling crud operations 1\ items collection field type description id objectid auto generated primary key title string the item’s title description string a short description of the item created at date timestamp marking item creation updated at date timestamp for the most recent update 2\ users collection field type details id objectid auto generated primary key username string unique identifier for the user email string unique email address password hash string encrypted password for security created at date timestamp when the account was created updated at date timestamp for the latest account update you can manually create these collections on the back4app dashboard by establishing new classes and adding corresponding columns create new class easily add new fields by choosing a data type, naming the field, and specifying any default values or required parameters create column leveraging the back4app ai agent for schema creation the back4app ai agent, accessible from your dashboard, automatically generates a database schema based on a prompt detailing your collections and fields this feature is a huge time saver, ensuring your backend is precisely tailored for crud operations how to utilize the ai agent launch the ai agent access it via your project settings or main menu in the back4app dashboard input your schema details provide a descriptive prompt that lists the collections and fields you require review and confirm after the ai agent processes your request, review the generated schema and apply it to your project example prompt create the following collections in 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) using the ai agent ensures your schema is both consistent and optimized for your application’s requirements step 3 – activating the admin app and performing crud operations overview of the admin app the back4app admin app offers a no code interface for backend management its intuitive drag and drop design simplifies crud operations—allowing you to create, view, update, and delete records effortlessly activating the admin app go to the “more” menu on your back4app dashboard select “admin app” and then click on “enable admin app ” set up your admin credentials by creating an initial admin user, which will also establish roles (like b4aadminuser ) and system collections enable admin app after activation, sign in to the admin app to manage your backend data admin app dashboard managing data using the admin app inside the admin app, you can add records use the “add record” button in any collection (e g , items) to create new entries view/modify records click on a record to inspect its details or to edit its fields remove records utilize the delete function to eliminate data that is no longer needed this interface greatly enhances usability by streamlining all crud functions step 4 – connecting polymer with back4app with your backend configured via the admin app, it’s time to link your polymer frontend to back4app option a utilizing rest/graphql apis we will use rest or graphql apis to perform crud operations for example, to retrieve items using rest // example rest call to get items const fetchitems = async () => { try { const response = await fetch('https //parseapi back4app com/classes/items', { headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key' } }); const data = await response json(); console log('items fetched ', data results); } catch (error) { console error('error fetching items ', error); } }; fetchitems(); integrate similar api calls into your polymer elements as required step 5 – reinforcing backend security implementing access control lists (acls) safeguard your data by applying acls to objects for instance, to create a restricted item async function createrestricteditem(data, owner) { const itemdata = { title data title, description data description }; // configure acl to permit only the owner access const acl = { " " { read false, write false }, \[owner id] { read true, write true } }; try { const response = await fetch('https //parseapi back4app com/classes/items', { method 'post', headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key', 'content type' 'application/json' }, body json stringify({ itemdata, acl acl }) }); const result = await response json(); console log('restricted item created ', result); } catch (error) { console error('error creating item ', error); } } configuring class level permissions (clps) within the back4app dashboard, set up clps for each collection to define default access rules this configuration ensures only authorized users can access sensitive data step 6 – user authentication in polymer establishing user accounts back4app uses parse’s user class to manage authentication in your polymer project, implement user sign up and login as demonstrated below // example function for user registration using rest api async function signupuser(username, password, email) { try { const response = await fetch('https //parseapi back4app com/users', { method 'post', headers { 'x parse application id' 'your application id', 'x parse rest api key' 'your rest api key', 'content type' 'application/json' }, body json stringify({ username, password, email }) }); const result = await response json(); alert('user registered successfully!'); console log(result); } catch (error) { alert('registration error ' + error message); } } a similar approach can be adopted for login and session management, with additional features like email verification and password reset configured through the back4app dashboard step 7 – deploying your polymer frontend with web deployment back4app’s web deployment feature lets you host your polymer application seamlessly by linking your github repository follow these steps to deploy your app 7 1 building your production version open your project directory in a terminal execute the build command polymer build this command generates a build folder with all optimized static files check the build ensure that the build folder contains an index html file along with necessary asset directories 7 2 organizing and uploading your source code your repository should contain the complete source code for your polymer frontend a sample directory structure might look like basic crud app polymer frontend/ ├── node modules/ ├── public/ │ └── index html ├── src/ │ ├── my app js │ ├── api config js │ └── components/ │ ├── items list js │ └── auth form js ├── polymer json └── readme md example src/api config js // src/api config js export const app id = 'your application id'; export const rest api key = 'your rest api key'; export const api url = 'https //parseapi back4app com'; example src/my app js import { polymerelement, html } from '@polymer/polymer/polymer element js'; class myapp extends polymerelement { static get template() { return html` \<style> / your css styles here / \</style> \<h1>item manager\</h1> \<items list>\</items list> \<auth form>\</auth form> `; } } customelements define('my app', myapp); committing your code to github initialize a git repository (if not already done) git init stage your files git add commit your changes git commit m "initial commit for polymer frontend" create a github repository name it basic crud app polymer frontend push your code to github git remote add origin https //github com/your username/basic crud app polymer frontend git git push u origin main 7 3 connecting your github repository with web deployment access web deployment sign in to back4app, navigate to your project ( basic crud app polymer ), and select the web deployment feature integrate github follow the prompts to connect your github account, allowing back4app to access your repository select your repository and branch choose the repository (e g , basic crud app polymer frontend ) and the appropriate branch (e g , main ) 7 4 configuring deployment settings specify the following details build command if the build folder is not pre built, set the command (e g , polymer build ) back4app will execute this during deployment output directory set it to build so that back4app identifies your static site files environment variables include any necessary variables (such as api keys) in the deployment configuration 7 5 containerizing your polymer application with docker if docker is your deployment choice, include a dockerfile in your repository similar to \# use an official node image for building from node 16 alpine as builder \# set working directory workdir /app \# copy dependency files copy package json / \# install dependencies run npm install \# copy the project files copy \# build the polymer app run polymer build \# use nginx to serve the built files from nginx\ stable alpine copy from=builder /app/build /usr/share/nginx/html expose 80 cmd \["nginx", " g", "daemon off;"] integrate this dockerfile in your project and select docker as the deployment option in back4app 7 6 deploying your application click the deploy button once your settings are confirmed, hit deploy watch the build process back4app will fetch your code, run the build command, and deploy your containerized app retrieve your url after deployment, you will receive a url where your polymer application is accessible 7 7 testing your deployment visit the url open the provided link in your browser verify functionality check that all routes load correctly and that assets like css, javascript, and images display as expected troubleshoot if any issues occur, review the deployment logs and github integration settings on back4app step 8 – wrap up and future directions great job! you have successfully built a complete crud application using polymer and back4app your project, basic crud app polymer , now features well defined collections for items and users, managed seamlessly through the admin app, with a secure and integrated polymer frontend next steps enhance the frontend add features like detailed item views, search functionality, or real time updates expand functionality integrate additional backend logic with cloud functions or third party apis explore more check out the back4app documentation https //www back4app com/docs for more advanced configurations and performance optimizations with these skills, you’re well equipped to build scalable crud backends and deploy robust web applications with polymer and back4app happy coding!