In the world of application development, conditionals play a crucial role in controlling the flow of your program and executing specific actions based on certain conditions. Xano, the powerful no-code platform, makes it easy to implement conditionals in your backend services, empowering you to create sophisticated logic without writing a single line of code.
In this guide, we'll walk you through a practical example of using conditionals in Xano. We'll build a simple to-do list application with a reminder functionality that sends an email notification when a new task is added. Let's get started!
Create a new project: Log in to your Xano account and create a new project. For this example, we'll use the "To-Do List" template.
Configure SendGrid: Before we dive into conditionals, make sure you've configured the SendGrid extension in your Xano project. This extension allows you to send emails directly from your application. If you haven't set up SendGrid yet, watch the video on "How to Configure the SendGrid Extension" to get it up and running.
Navigate to the API page: In your Xano project, click on the "API" tab in the left-hand sidebar. This is where you'll find the CRUD (Create, Read, Update, Delete) API endpoints for your to-do list.
Open the POST endpoint for to-do: Locate the "POST" endpoint for the "to-do" resource. This endpoint is responsible for creating new to-do items.
Add a new input: In the "POST" endpoint, click on the "Inputs" tab and add a new Boolean input called "sendReminder". This input will determine whether we should send a reminder email or not.
Create a conditional: In the "Function Stack" tab, click on the "Add Function" button and select "Conditional". This will open a new window where you can define your conditional statement.
Set the condition: In the "If" section, click on the "Edit" button. A new window will appear where you can define your condition. Set the condition to sendReminder === true. This means that the code inside the "Then" block will execute only if the "sendReminder" input is set to true.
Send the email: Inside the "Then" block, click on the "Add Function" button and select "Custom Functions" > "SendGrid Basic Send". This function will allow you to send an email using the SendGrid extension.
Configure the email inputs: In the SendGrid function, map the inputs as follows:
To Email: Enter your email address (e.g., your@email.com)Subject: Set the subject to "Reminder"Text: Map this input to the task input from the POST endpoint. This way, the email body will contain the task description.task input to a new to-do item (e.g., "Make more Xano videos"), set completed to false, important to true, and sendReminder to true. Click "Run" and check your email inbox for the reminder notification.Congratulations! You've successfully implemented a conditional statement in Xano and integrated it with the SendGrid extension to send email reminders for new to-do items.
Conditionals in Xano are incredibly powerful and can be used in various scenarios. Here are a few ideas to take your conditional logic to the next level:
Xano's visual interface and no-code approach make it easy to experiment with conditionals and build sophisticated applications without writing a single line of code. Whether you're a no-code enthusiast, a citizen developer, or a traditional developer, Xano empowers you to bring your ideas to life quickly and efficiently.
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free