Quickstarters

How to Build a Backend for Elixir?

39min

Introduction

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.

Prerequisites

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.

Step 1 – Creating a New Project on Back4App and connecting

Create a New Project

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:

  1. Log in to your Back4app account.
  2. Click the “New App” button in your Back4App dashboard.
  3. Give your app a name (e.g., “Elixir-Backend-Tutorial”).
Document image


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.

Connecting via REST or GraphQL

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:

  1. Retrieve your Application ID and REST or GraphQL Keys from your app’s “App Settings” or “Security & Keys” section in the Back4App dashboard.
  2. Configure HTTP requests using an Elixir library such as HTTPoison or Tesla.

For example, to store credentials in a config file (config/dev.exs or similar):

Text


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.

Step 2 – Setting Up the Database

Creating a Data model

In Back4App, data is stored in classes. You can create a new class in the Back4App dashboard:

  1. Navigate to the “Database” section in your Back4App dashboard.
  2. Create a new class (e.g., “Todo”) and add relevant columns, such as title (String) and isCompleted (Boolean).
Create New Class
Create New Class


Creating a Data model using the AI Agent

Back4App also provides an AI Agent to help you describe and create your data model:

  1. Open the AI Agent from your App Dashboard or the menu.
  2. Describe your data model in plain language (e.g., “Please, create a new Todo App with a complete class schema.”).
  3. Let the AI Agent create the schema automatically.
Document image


Reading and Writing Data using SDK (If Applicable)

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.

Reading and Writing Data using REST API

Install an HTTP client like HTTPoison in your mix.exs:

Text


Then, run mix deps.get.

To create (save) a Todo object from your Elixir application:

Text


And to query your Todo objects:

Text


Reading and Writing Data using GraphQL API

You can also interact via GraphQL. For example, creating a Todo:

GraphQL


In Elixir, you might send this with an HTTP client as well:

Text


Working with Live Queries (Optional)

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.

Step 3 – Applying Security with ACLs and CLPs

Brief Overview

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.

Document image


Step-by-step

  1. 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).
  2. 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.
Edit ACL
Edit ACL


For more information, visit the App Security Guidelines.

Step 4 – Writing Cloud Code Functions

Why Cloud Code

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.

Example Function

In your main.js on the Back4App Dashboard or using the CLI:

JS


Deployment

Deploy via the Back4app CLI or by pasting into the dashboard under Cloud Code > Functions and clicking Deploy.

Document image


Calling Cloud Code

From Elixir, you might use:

Text


Step 5 – Configuring Authentication

Enable or Set Up Authentication

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:

Text


Social Login

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.

Step 6 – Handling File Storage

Setting up File Storage

Back4App stores files securely. From Elixir, you’d upload files via REST:

Text


You’ll receive a JSON response with the file URL, which you can store in a class (e.g., Photo) for reference.

Security Considerations

You can configure who can upload files in fileUpload settings on your Back4App project, restricting uploads to authenticated users if desired.

Step 7 – Email Verification and Password Reset

Overview

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.

Back4App Dashboard Configuration

  1. Enable email verification under your app’s “App Settings” or “Authentication.”
  2. Configure the From address and email templates.
  3. Enable password reset to let users reset via a link emailed to them.

Code/Implementation

Once enabled in the dashboard, you can trigger password resets:

Text


Step 8 – Scheduling Tasks with Cloud Jobs

What Cloud Jobs Do

Cloud Jobs let you automate routine tasks like cleaning old data or sending periodic emails. You write them in Cloud Code.

Example

JS

  1. Deploy the code.
  2. Go to the Back4app Dashboard > App Settings > Server Settings > Background Jobs.
  3. Schedule the job to run daily or at a frequency you choose.
Scheduling a Cloud Job
Scheduling a Cloud Job


Step 9 – Integrating Webhooks

Definition

Webhooks allow your Back4App application to send HTTP requests to an external service (e.g., a Slack channel or Stripe) when certain events occur.

Configuration

  1. Navigate to the Webhooks configuration in your Back4App dashboard > More > Webhooks.
  2. Set the endpoint (for example, https://your-service.com/webhook-endpoint).
  3. Configure triggers such as “New record in the Todo class.”
Adding a Webhook
Adding a Webhook


Example

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.

BeforeSave WebHook
BeforeSave WebHook


Step 10 – Exploring the Back4App Admin Panel

Where to Find It

The Back4app Admin App is a user-friendly interface for managing your data. You can enable it from App Dashboard > More > Admin App.

Enable Admin App
Enable Admin App


Features

  1. Create a First Admin User, which sets up the B4aAdminUser role and additional classes.
  2. Assign a Subdomain to access the admin interface.
  3. Log in to view and manage data in a simple interface.
Document image


Conclusion

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.

Next Steps

  • 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!