Quickstarters
CRUD Samples
How to Create a CRUD Application with Remix?
34 min
overview in this walkthrough, you'll learn how to build a crud (create, read, update, delete) application using remix js we'll be using back4app as our backend service to handle data storage seamlessly this guide covers setting up a back4app project, designing a dynamic data schema, and wiring up crud operations in your remix js application initially, you'll set up a back4app project, which we'll call basic crud app remix , providing a scalable non relational data store you'll then create a data model by manually establishing collections and fields via the back4app dashboard, or even use the integrated ai agent for an automated setup next, you'll explore the back4app admin app—a user friendly interface that lets you easily manage your data using drag and drop operations finally, you'll connect your remix js application to back4app through rest api calls, ensuring that your crud functionalities, along with user authentication, are robust and secure by the end of this tutorial, you'll have a production ready remix js application capable of performing basic crud operations along with secure user management what you will learn how to build a crud app with remix js and a reliable backend best practices for structuring your backend and integrating it with a remix js frontend how to use the back4app admin app to simplify data management tasks techniques for deploying your remix js application, including containerization with docker prerequisites before you begin, make sure you have a back4app account with a new project ready need help? visit getting started with back4app https //www back4app com/docs/get started/new parse app a working remix js development environment you can use any modern code editor like vs code node js (version 14 or later) should be installed basic knowledge of javascript, react, and restful apis for a refresher, check out the remix documentation https //remix run/docs step 1 – setting up your project launching a new back4app project log in to your back4app account hit the “new app” button from your dashboard name your project basic crud app remix and follow the steps to complete the creation process create new project once your project is ready, it will appear on your dashboard, providing the foundation for your backend step 2 – crafting your data model establishing data structures for this crud application, you'll define several collections in back4app below are examples of the main collections and fields that will support your crud functionalities 1\ items collection this collection will store details about each item field data type description id objectid automatically generated unique identifier title string the name or title of the item description string a brief summary describing the item createdat date timestamp for when the item was added updatedat date timestamp for the last modification 2\ users collection this collection manages user credentials and authentication information field data type description id objectid auto generated unique identifier username string unique username for the user email string unique email address of the user passwordhash string hashed password for secure authentication createdat date timestamp for when the account was created updatedat date timestamp for when the account was updated you can create these collections and add fields directly from the back4app dashboard create new class to add a new field, simply choose a data type, input the field name, and set default values or mandatory options as needed create column using the back4app ai agent for schema generation the ai agent integrated into back4app can auto generate your schema based on your description, streamlining the initial setup how to use the ai agent access the ai agent log into your back4app dashboard and find the ai agent in your project settings describe your data model provide a detailed explanation of the collections and fields you need review and confirm the ai agent will present a proposed schema verify the details and confirm the setup example prompt create the following collections in my back4app project 1\) collection items \ fields \ id objectid (auto generated) \ title string \ description string \ createdat date (auto generated) \ updatedat date (auto updated) 2\) collection users \ fields \ id objectid (auto generated) \ username string (unique) \ email string (unique) \ passwordhash string \ createdat date (auto generated) \ updatedat date (auto updated) this ai assisted method speeds up the process and ensures your schema is perfectly tailored to your app's needs step 3 – activating the admin app & handling crud operations overview of the admin app the back4app admin app provides a no code interface that simplifies backend data management its drag and drop features make crud operations—like adding, editing, and deleting records—more intuitive enabling the admin app head over to the “more” menu in your back4app dashboard select “admin app” and click on “enable admin app ” set up your admin account by entering your credentials this will also configure roles (e g , b4aadminuser ) and system classes enable admin app after activation, log into the admin app to manage your data with ease admin app dashboard performing crud tasks via the admin app inside the admin app, you can insert new records use the “add record” button within a collection (such as items) to create new entries inspect and modify records click on any record to see its details and make edits delete records remove any records that are no longer required this intuitive interface greatly enhances your data management experience step 4 – connecting your remix js application with back4app now that your backend is set up, it’s time to integrate your remix js app with back4app using rest api calls in remix js since the parse sdk is not typically used with remix js, you'll perform crud operations via rest api requests 1\ setting up your remix js project if you haven’t already, create a new remix project npx create remix\@latest follow the prompts to choose your deployment target 2\ making api requests from remix create api route files under the app/routes directory to handle crud operations for example, you might have a file called items server js that includes functions for fetching, creating, updating, and deleting items example fetching items // app/routes/items server js import { json } from "@remix run/node"; export async function loader() { const response = await fetch("https //parseapi back4app com/classes/items", { method "get", headers { "x parse application id" "your application id", "x parse rest api key" "your rest api key", }, }); const data = await response json(); return json(data); } similarly, you can create post, put, and delete routes to handle item creation, updates, and deletions 3\ connecting ui components in your remix components, you can use hooks like useloaderdata to fetch data and fetch api or action functions to send data back to back4app for example, in your react component // app/routes/items jsx import { useloaderdata, form } from "@remix run/react"; export default function items() { const data = useloaderdata(); return ( \<div> \<h1>items list\</h1> {data results map((item) => ( \<div key={item objectid}> \<h2>{item title}\</h2> \<p>{item description}\</p> \</div> ))} \<form method="post"> \<input type="text" name="title" placeholder="item title" required /> \<textarea name="description" placeholder="item description" required /> \<button type="submit">add item\</button> \</form> \</div> ); } integrate similar api calls for update and delete operations in your remix actions step 5 – securing your backend implementing access control lists (acls) strengthen data security by setting acls for your objects for instance, to create an item that is accessible only by its creator // example api call to create a private item using acls async function createprivateitem(title, description, usersessiontoken) { 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", "x parse session token" usersessiontoken, }, body json stringify({ title, description, acl { " " { "read" false, "write" false }, "user object id" { "read" true, "write" true } }, }), }); return response json(); } class level permissions (clps) adjust clps in your back4app dashboard to enforce default security policies, ensuring that only authenticated users can access specific collections step 6 – adding user authentication configuring user management back4app utilizes parse’s built in user class for managing authentication in your remix application, handle user registration and login using api calls example user registration endpoint // app/routes/signup server js import { json, redirect } from "@remix run/node"; export async function action({ request }) { const formdata = await request formdata(); const username = formdata get("username"); const password = formdata get("password"); const email = formdata get("email"); 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 }), }); if (!response ok) { throw new error("signup failed"); } return redirect("/login"); } implement similar endpoints for login, session management, and password resets step 7 – deploying your remix js application back4app supports seamless deployment you can deploy your remix js app using various strategies, including docker 7 1 building your remix js application compile and bundle use your package manager and build scripts (e g , via npm run build ) to compile your app verify the output ensure your build output contains all necessary files 7 2 project structure example a typical remix js project may look like basic crud app remix/ \| app/ \| | routes/ \| | | items jsx \| | | items server js \| | | signup server js \| | components/ \| | itemform jsx \| public/ \| package json \| remix config js \| readme md 7 3 dockerizing your application if you choose containerization, add a dockerfile in your project’s root \# use an official node js runtime as a base from node 16 alpine \# set the working directory in the container workdir /app \# copy package files and install dependencies copy package json package lock json / run npm install \# copy the rest of the application code copy \# build the remix app run npm run build \# expose the port the app runs on expose 3000 \# start the application cmd \["npm", "start"] 7 4 deploying via back4app web deployment connect your repository host your remix js source code on github configure deployment in your back4app dashboard, select the web deployment feature, link your repository (e g , basic crud app remix ), and choose the correct branch set build and output commands specify your build command (like npm run build ) and the output directory deploy your app click deploy and monitor the logs until your app is live step 8 – wrapping up and future directions well done! you’ve now built a crud application using remix js integrated with back4app in this guide, you set up a project called basic crud app remix , defined collections for items and users, and managed data through the back4app admin app you then connected your remix js app to back4app via rest api calls, and implemented secure user authentication and data protection measures next steps enhance your application consider adding more features like search functionality, detailed item views, or real time updates expand backend capabilities look into cloud functions, external api integrations, or more advanced access control keep learning visit the back4app documentation https //www back4app com/docs and explore additional remix js tutorials to further optimize your app happy coding and best wishes on your remix js journey!