How to Build a Backend for Elixir?
In this tutorial, you’ll learn how to build a backend for Elixir using Back4App.
We’ll walk through integrating essential Back4App features—such as database management, Cloud Code Functions, REST and GraphQL APIs, user authentication, and real-time queries (Live Queries)—to create a secure, scalable, and robust backend.
Elixir, running on the Erlang VM (BEAM) and leveraging OTP (Erlang OTP), is known for its fault-tolerant, concurrent environment, which pairs well with Back4App to form a modern, high-performance infrastructure.
You’ll see how Back4App’s quick setup and intuitive environment can drastically reduce your time and effort compared to manually configuring servers and databases.
This includes leveraging pattern matching, plus hooking into Elixir’s web framework of choice.
By the end of this tutorial, you’ll have a solid foundation you can extend into a production-ready application or enhance with custom logic and third-party APIs.
To complete this tutorial, you will need:
- A Back4App account and a new Back4App project Getting Started with Back4app. If you do not have an account, you can create one for free. Follow the guide above to get your project ready.
- Basic Elixir development environment Ensure you have Elixir installed on your machine. If you plan to use a web framework such as Phoenix, see the Phoenix installation guide for reference.
- Familiarity with Elixir concepts Elixir Official Documentation. If you’re new to Elixir, review these resources or a beginner’s tutorial before starting.
Make sure you have all these prerequisites in place before you begin. Having your Back4App project set up and your local Elixir environment ready will help you follow along more smoothly.
The first step in how to build a backend for Elixir on Back4App is creating a new project. If you have not already created one, follow these steps:
- Log in to your Back4app account.
- Click the “New App” button in your Back4App dashboard.
- Give your app a name (e.g., “Elixir-Backend-Tutorial”).
Once the project is created, you will see it listed in your Back4App dashboard. This project will be the foundation for all backend configurations discussed in this tutorial.
Back4App uses the Parse platform as a foundation. For Elixir, there is no official Parse SDK at the moment. Instead, you can easily connect to Back4App using the REST or GraphQL APIs. In your Elixir project, you’ll:
- Retrieve your Application ID and REST or GraphQL Keys from your app’s “App Settings” or “Security & Keys” section in the Back4App dashboard.
For example, to store credentials in a config file (config/dev.exs or similar):
You can then reference these credentials in your code to make REST calls. Throughout this guide, we’ll showcase how to interact with the Back4App database, user system, and other features using standard HTTP or GraphQL requests.
In Back4App, data is stored in classes. You can create a new class in the Back4App dashboard:
- Navigate to the “Database” section in your Back4App dashboard.
- Create a new class (e.g., “Todo”) and add relevant columns, such as title (String) and isCompleted (Boolean).
Back4App also provides an AI Agent to help you describe and create your data model:
- Open the AI Agent from your App Dashboard or the menu.
- Describe your data model in plain language (e.g., “Please, create a new Todo App with a complete class schema.”).
- Let the AI Agent create the schema automatically.
Since Elixir does not have an official Parse SDK, we’ll skip direct SDK usage. Instead, we’ll showcase REST, GraphQL, and Live Queries approaches below.
Install an HTTP client like HTTPoison in your mix.exs:
Then, run mix deps.get.
To create (save) a Todo object from your Elixir application:
And to query your Todo objects:
You can also interact via GraphQL. For example, creating a Todo:
In Elixir, you might send this with an HTTP client as well:
For real-time updates, Back4App offers Live Queries. You can enable Live Queries in your app’s Server Settings. Since there’s no native Elixir Parse client library at the moment, you’d typically connect through a Phoenix channel or any custom WebSocket client to the provided wss://YOUR_SUBDOMAIN_HERE.b4a.io endpoint. This can be more advanced, requiring custom coding to handle subscriptions, messages, etc.
Back4App offers Access Control Lists (ACLs) and Class-Level Permissions (CLPs) to protect and manage data access. ACLs apply to individual objects, while CLPs apply to the entire class.
- Class-Level Permissions (CLPs): In your Back4App Dashboard, under Database, select a class (e.g., “Todo”) and open the Class-Level Permissions tab. Adjust settings (e.g., “Requires Authentication” or “No Access” for the public).
- Configure ACLs: When creating or updating an object, you can send ACL data in your REST or GraphQL request. For instance, specify the _ACL field in JSON if you need fine-grained per-object control.
For more information, visit the App Security Guidelines.
Cloud Code lets you run server-side logic without managing your own servers. With Elixir, you usually rely on OTP for concurrency, but here you can simply create JavaScript Cloud Code in Back4App to handle validation, triggers, or custom business logic. This code runs on Parse Server, so you can keep your Elixir code focused on client or microservice tasks while the heavy lifting happens in Cloud Code.
In your main.js on the Back4App Dashboard or using the CLI:
Deploy via the Back4app CLI or by pasting into the dashboard under Cloud Code > Functions and clicking Deploy.
From Elixir, you might use:
Back4App uses the Parse User class for authentication. You can manage sign-up, login, and password resets easily. From Elixir, you’ll typically use REST calls:
Back4App supports integration with Google, Apple, Facebook, and more. In most cases, you’ll direct users to the OAuth flow, then use tokens returned by these providers to complete the Parse login. See Social Login Docs for details.
Back4App stores files securely. From Elixir, you’d upload files via REST:
You’ll receive a JSON response with the file URL, which you can store in a class (e.g., Photo) for reference.
You can configure who can upload files in fileUpload settings on your Back4App project, restricting uploads to authenticated users if desired.
Email verification ensures that users own the email address used during sign-up. Password reset lets them recover accounts securely. Both features are built in on Back4App.
- Enable email verification under your app’s “App Settings” or “Authentication.”
- Configure the From address and email templates.
- Enable password reset to let users reset via a link emailed to them.
Once enabled in the dashboard, you can trigger password resets:
Cloud Jobs let you automate routine tasks like cleaning old data or sending periodic emails. You write them in Cloud Code.
- Deploy the code.
- Go to the Back4app Dashboard > App Settings > Server Settings > Background Jobs.
- Schedule the job to run daily or at a frequency you choose.
Webhooks allow your Back4App application to send HTTP requests to an external service (e.g., a Slack channel or Stripe) when certain events occur.
- Navigate to the Webhooks configuration in your Back4App dashboard > More > Webhooks.
- Set the endpoint (for example, https://your-service.com/webhook-endpoint).
- Configure triggers such as “New record in the Todo class.”
If you want to send data to Slack whenever a Todo is created, you can add a new webhook pointing to your Slack incoming webhook URL. You might also define Webhooks in Cloud Code by sending custom HTTP requests in triggers like afterSave.
The Back4app Admin App is a user-friendly interface for managing your data. You can enable it from App Dashboard > More > Admin App.
- Create a First Admin User, which sets up the B4aAdminUser role and additional classes.
- Assign a Subdomain to access the admin interface.
- Log in to view and manage data in a simple interface.
By following this tutorial on how to build a backend for Elixir with Back4App, you have:
- Created a secure backend structure on Back4App’s platform using Elixir for integration.
- Set up a database with classes, data types, and relationships.
- Used REST/GraphQL to interact with your data from Elixir.
- Applied security using ACLs and CLPs.
- Added custom logic with Cloud Code functions.
- Configured user authentication with email verification and password resets.
- Handled file storage and retrieval.
- Scheduled background jobs for automation.
- Integrated external services with webhooks.
- Explored the Back4App Admin Panel for easy data management.
With Elixir’s concurrency model (powered by the Erlang VM) and OTP, combined with Back4App’s scalable and flexible services, you can build highly robust backends.
Continue exploring more advanced features, integrate your business logic, and let Back4App help you handle the heavy lifting.
- Build a production-ready Elixir app by layering this backend with your preferred Elixir/Phoenix web framework.
- Integrate advanced features like role-based access control or third-party APIs (payment gateways, messaging services).
- Explore Back4app’s official documentation for advanced security, logs, performance tuning, and more.
- Check out other tutorials for real-time apps, IoT dashboards, or location-based services. With pattern matching and OTP concurrency at your disposal, you’re equipped to tackle a wide range of applications!