Skip to content

Introduction to PocketBase: A Backend Alternative for Xojo Developers

Introduction

When developing applications with Xojo, choosing the right backend is crucial for managing data efficiently. Traditionally, Xojo developers rely on SQL databases such as SQLite, MySQL, or PostgreSQL for their desktop, web, and mobile applications. However, there is an alternative that provides a more flexible and modern approach to backend development: PocketBase.

PocketBase is an open-source backend perfect for your multi-platform Xojo application. It offers a simple-to-use API and a built-in admin panel to manage the data from any web browser. No other tool such as MySQL, Workbench, or SQL Studio is needed. In this post, I will explain how it compares to traditional SQL databases and demonstrate how to integrate it into a Xojo project.

Why Choose PocketBase for Your Xojo App Backend?

PocketBase is a lightweight, self-hosted backend designed for simplicity and flexibility. Unlike traditional SQL databases that require a separate backend service or API layer, PocketBase is an all-in-one solution that combines the database and API.

Key Features:

Embedded Database – Powered by SQLite, eliminating the need for a separate database server.

Built-in User Authentication – Supports email/password logins, OAuth2 sign-ups, and one-time password (OTP) with minimal setup.

File Storage – Store and retrieve files locally or via S3.

Cross-Platform Compatibility – Runs on macOS, Windows, and Linux. Can communicate via URLConnection making it ideal for Xojo’s desktop, web, and mobile platforms.

Easy Deployment – A single binary file that can be self-hosted or deployed anywhere with minimal configuration.

Setting Up PocketBase for a Xojo App

To get started, I have simplified some steps below. If you get stuck or want more in-depth instructions take a look at the documentation.

  • Download PocketBase
    • Visit PocketBase and download the latest release for your operating system.
    • Extract the files to your project directory.
  • Run PocketBase
    • Start the PocketBase server by navigating to the extracted folder in the command prompt/terminal.
    • Run the command: ./pocketbase serve to start the server.
  • Access the Admin Panel
    • Open http://127.0.0.1:8090/_/ in a web browser and set up an admin account.
  • Add a User
    • In the PocketBase admin panel, create a new record in the users collection. (Collections are the equivalent of a table in SQL.)

Connect Xojo to PocketBase

Now that your PocketBase server is running, integrate authentication into your Xojo desktop app. In this example, we will handle authentication in the open event of the main window. This will demonstrate how Xojo interacts with PocketBase’s authentication API.

Implement the Login Request

Add the following code to the open event of your main window:

Var userEmail As String = "email@email.com"
Var userPassword As String = "MyPassword!"
Var loginURL As String = "http://127.0.0.1:8090" + "/api/collections/users/auth-with-password"
Var conn As New URLConnection
conn.RequestHeader("Content-Type") = "application/json"
 
Var loginPayload As New JSONItem
loginPayload.Value("identity" ) = userEmail
loginPayload.Value("password") = userPassword
conn.SetRequestContent(loginPayload.ToString, "application/json")
 
Var loginResponse As String = conn.SendSync("POST", loginURL)
Var jsonResponse As New JSONItem(loginResponse)
Var userInfo As JSONItem = jsonResponse.Lookup("record", New JSONItem)
Var userID As String = userInfo.Lookup("id", "")
Var authToken As String = jsonResponse.Lookup("token", "")
 
If authToken.Length > 0 Then
  MessageBox("Login successful! Welcome, User ID: " + userID)
Else
  MessageBox("Login failed. Please check your credentials.")
End If

Update Your Credentials and URL

Replace userEmail and userPassword with the credentials you used to create a user in PocketBase. Also, ensure the loginURL matches your PocketBase instance (without /_/ at the end).

Run The App

Launch your Xojo app. If authentication is successful, a message box will display the user’s ID. Otherwise, you will see an error message indicating that the credentials are incorrect.

Wrapping Up

In this article, you have successfully set up a PocketBase server, created a record, and integrated authentication into your Xojo app. PocketBase simplifies backend development by handling authentication and data storage—all without the need for a traditional SQL database.

With PocketBase, there is no need to set up complex user tables, hash passwords, or build a custom API. Collections can be easily managed directly from the web via the admin panel. This means you can spend less time managing infrastructure and more time focusing on bringing your app to market.

To help you get started, I’ve created a collection of example projects, which you can find here:

Xojo-Pocketbase-Examples

If you’d like to discuss how Iron Elephant Solutions has used Xojo and PocketBase in real-world applications, feel free to reach out through our website or add me on LinkedIn.

Ezekiel Burke is the founder of Iron Elephant Solutions. He focuses on building custom, scalable, and affordable software that helps businesses work smarter. With 15+ years of experience, he specializes in full-stack development, process automation and systems integration, creating solutions that simplify complex workflows.