Api And Debugging

Addons (similar to Graph QL)

Building robust applications often requires integrating data from multiple sources. Xano's add-ons feature provides a powerful solution for seamlessly extending your API responses with related data, ensuring you have all the information you need in a single request. In this guide, we'll walk you through the process of creating and utilizing add-ons, unlocking the potential for efficient data integration within your Xano application.

Understanding Add-Ons

Add-ons in Xano are similar to GraphQL, but within a REST API framework. They allow you to combine data from different sources into a single API response, eliminating the need for multiple requests. Think of it like a Facebook wall post, which pulls together various pieces of information, such as likes, comments, and relationships, into a cohesive view.

Creating an Add-On

Let's dive into an example to illustrate the process of creating an add-on. Imagine you have a loyalty card application with three tables: users, merchants, and deals. You want to retrieve a list of merchants along with their associated deals in a single API response.

  1. Navigate to the API Query: Go to the API query for retrieving merchants (e.g., GET /merchants).

  2. Add an Add-On: In the query's output section, click the "Add-On" button.

  3. Choose the Table: Select the deals table as the source for the additional data you want to include.

  4. Select the Return Type: Choose how you want the data returned. In this case, select "List of Items" to retrieve all deals associated with each merchant.

  5. Map the Relationship: Specify how the deals table relates to the merchants table. If the deals table has a merchant_id column referencing the merchants table's id, map the relationship accordingly.

  6. Customize and Save: Name your add-on, review the input routing, and optionally customize the response structure. Then, click "Save" to apply the changes.

Now, when you execute the GET /merchants API query, the response will include the merchant data along with a list of associated deals for each merchant.

Recursive Add-Ons

The true power of add-ons lies in their recursive nature. You can continue adding data from other tables based on the initial response or the newly added data. For example, let's say you want to check if an authenticated user has used a particular deal. You can create another add-on on the deals data, this time referencing the ledger table (a transaction table tracking deal usage).

  1. Add a New Add-On: Click the "Add-On" button again, this time within the deals section of the response.

  2. Choose the Table: Select the ledger table.

  3. Select the Return Type: Since you only need to check for existence, choose the "Existence" return type.

  4. Map the Relationship: Map the deal_id from the deals table and the user_id from the authenticated user.

  5. Customize and Save: Review the input routing, optionally customize the response structure, and click "Save" to apply the changes.

Now, when you execute the API query as an authenticated user, the response will include a flag indicating whether the user has used each deal or not, based on the data in the ledger table.

Advanced Customization

While the add-on creation process within API queries is straightforward, Xano also provides an "Add-Ons" page in the library for more advanced customization. Here, you can create and manage add-ons independently, allowing for precise control and complex configurations when needed.

Conclusion

Xano's add-ons feature is a game-changer for efficient data integration within your applications. By combining related data from multiple sources into a single API response, you can streamline your development process, reduce redundant requests, and provide a seamless user experience. Whether you're a no-code enthusiast, a citizen developer, a traditional developer, or a startup/small business, add-ons empower you to build robust applications with ease. Embrace the power of add-ons and unlock new possibilities in your Xano journey.

Sign up for Xano

Join 100,000+ people already building with Xano.

Start today and scale to millions.

Start building for free