Wix Velo, the open platform by Wix, empowers developers to build, deploy, and manage dynamic web applications faster and more efficiently. With its rich set of APIs, SDKs, and a robust plugin repository, Velo enables you to extend the capabilities of your Wix sites beyond what's available out-of-the-box. Let's explore some practical Velo examples to bring your development skills to the next level.

Whether you're a seasoned developer looking to streamline your workflow or a beginner eager to learn, leveraging Velo examples canിലേ accelerate your proficiency. We'll dive into two main topics: Serverless Functions and Data Integration, with examples for each sub-topic.

Serverless Functions
Serverless Functions allow you to run backend code without managing servers, making them an essential Velo feature. You can use them to create APIs, process form submissions, and more.

Wix provides a simple JSON API to create and manage Serverless Functions. Let's look at two examples: creating a new function and invoking it to retrieve data.
Create a Serverless Function

First, let's create a simple 'Hello, World!' function using Wix's Velo Manager. In the Velo workspace, navigate to "Functions" and click on "Create Function". Name your function (e.g., 'hello-world'), select the 'Node.js' runtime, and input the following code:
{code}>module.exports = async (ctx) => {
return "Hello, World!";
};{code}
Click "Create" to deploy your function. You'll receive a function ID that you can use to invoke this function.
Invoke a Serverless Function

Now, let's create an HTML button that invokes the 'hello-world' function and displays its response. In your Wix Editor, add a new HTML element, and insert the following code:
<button onclick="wixData.request('{{YourFunctionID}}').then(response => {
alert(response);
})">Say Hello</button>
Replace '{{YourFunctionID}}' with the function ID you received earlier. When you click the button, it will call the 'hello-world' function and display the response.
Data Integration

Velo's data management capabilities let you work with databases, APIs, and other data sources seamlessly. Here, we'll explore two examples: fetching data from a JSONPlaceholder API and displaying it on your site, and creating a custom database and fetching data from it.
Fetching Data from a JSONPlaceholder API









JSONPlaceholder (https://jsonplaceholder.typicode.com/) is a simple mock API. We'll fetch 'To-Dos' data and display it on our site. In your Velo workspace, create a new Serverless Function, name it 'fetchToDos', and add the following code:
{code}>const response = await fetch('https://jsonplaceholder.typicode.com/todos');
const data = await response.json();
return data;'Code>
Now, in your Wix Editor, add an HTML element (e.g., a Repeat element) and set its "Data" field to '{{fetchToDos.Data}}'. Map the "Title" field to display each to-do's title.
Creating a Custom Database and Fetching Data
Let's create a simple database with a single 'Contact' collection and add a new contact. In Velo Manager, navigate to "Data" > "Databases" and click "Create Database". Name it 'contact-database' and create a collection called 'contacts'.
Create a new Serverless Function, name it 'addContact', and input the following code to populate the database:
{code}>const response = await wixData.query('contact-database').add({
name: 'John Doe',
email: 'johndoe@example.com'
});
return response;'Code>
Finally, create another Serverless Function, 'fetchContacts', to retrieve the data:
{code}>const response = await wixData.query('contact-database').find(); return response.items;'Code>
In your Wix Editor, use the fetched data to populate an HTML element, similar to the previous JSONPlaceholder example.
Incorporating these Velo examples into your web development workflow will enable you to create dynamic, feature-rich websites with ease. Happy coding!