Hey there! In this blog post, we'll show you how to connect your Xano backend with Bubble, a popular no-code platform for building web and mobile applications. By integrating these two powerful tools, you can leverage Xano's robust and scalable backend while utilizing Bubble's user-friendly interface for building your frontend.
Prerequisites
Before we dive in, make sure you have the following:
- An active Xano account with a workspace set up (if you don't have one yet, you can sign up for free at xano.io).
- A Bubble account and a new or existing project you want to connect with Xano.
Step 1: Install the Bubble API Connector Plugin
First, we need to install the Bubble API Connector plugin, which will allow us to connect Bubble with external APIs like Xano's.
- In your Bubble project, click on "Plugins" in the left-hand menu.
- Click "Add a plugin" and search for "API Connector."
- Click "Install" on the API Connector plugin.
- Once installed, click "Done."
Step 2: Set Up the Xano API Connection
Now that the API Connector plugin is installed, we can set up the connection to the Xano API.
- In the API Connector plugin, click "Add another API."
- Give your API a name (e.g., "Xano API").
- Click "Add another API call."
Get All Products
Let's start by setting up an API call to fetch all products from your Xano database.
- In the new API call, expand the settings and give it a name like "Get Products."
- Set the "Command" to "GET."
- Copy the URL for the "Get All Products" API endpoint from your Xano workspace (you can find it under the "APIs" section).
- Paste the URL into the "URL" field in Bubble.
- Click "Initialize call" to confirm the data structure.
- Click "Save."
Get a Single Product
Next, we'll set up an API call to fetch a single product by its ID.
- Click "Add another API call."
- Give it a name like "Get Single Product."
- Set the "Command" to "GET."
- Copy the URL for the "Get Product by ID" API endpoint from your Xano workspace.
- Paste the URL into the "URL" field in Bubble, but replace the `{id}` part with `{:id}` (e.g., `https://your-workspace.xano.io/api/products/{:id}`).
- In the "Parameters" section, add a new parameter with the key "id" and set its value to the ID of an existing product in your Xano database (e.g., `1`).
- Uncheck the "Private" checkbox for the "id" parameter.
- Click "Initialize call" to confirm the data structure.
- Click "Save."
Login a User
To authenticate users and access protected API endpoints, we'll set up an API call for user login.
- Click "Add another API call."
- Give it a name like "Login User."
- Set the "Command" to "POST."
- Copy the URL for the "Auth Login" API endpoint from your Xano workspace.
- Paste the URL into the "URL" field in Bubble.
- Change the "Use as" setting to "Action."
- In the "Body" section, paste the following JSON structure:
json
{
"email": "{:email}",
"password": "{:password}"
}
- For the "email" and "password" fields, uncheck the "Private" checkbox.
- Set the "email" value to a valid email address for a user in your Xano database (e.g., `prakash@email.com`).
- Set the "password" value to the corresponding password for that user (e.g., `password123`).
- Click "Initialize call" to confirm the data structure. You should receive an authentication token in the response.
- Click "Save."
Access a Protected API Endpoint
Finally, let's set up an API call to access a protected API endpoint that requires authentication.
- In your Xano workspace, go to the API endpoint you want to access (e.g., "Get All Products") and mark it as "Locked" to require authentication.
- Back in Bubble, click "Add another API call."
- Give it a name like "Xano Login."
- Set the "Command" to "GET."
- Copy the URL for the protected API endpoint from your Xano workspace.
- Paste the URL into the "URL" field in Bubble.
- Click "Add header."
- For the "Key," enter `Authorization`.
- For the "Value," enter `Bearer ` followed by the authentication token you received from the "Login User" API call (e.g., `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...`).
- Click "Initialize call" to confirm the data structure. You should now receive the data from the protected API endpoint.
- Click "Save."
Congratulations! You've successfully connected your Xano backend with Bubble. From here, you can start building your application's frontend in Bubble while leveraging the power and scalability of Xano's backend services.
Remember, this guide only covers the basics of connecting Xano and Bubble. For more advanced tutorials on displaying data, handling user interactions, and building complex workflows, be sure to check out the additional resources provided by Xano and Bubble.
Happy building!