Wix Velo Tutorials: Master Coding Wix Velo Examples: See in Action Boost Wix Sites with Velo

By Benjamin

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.

an image of a website page with cooking utensils on the front and back
an image of a website page with cooking utensils on the front and back

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.

How To Use Wix Velo Code
How To Use Wix Velo Code

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.

a man riding a bike on top of a poster
a man riding a bike on top of a poster

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

the google sheets page for an application
the google sheets page for an application

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

Cowboy | eCommerce Website Design Gallery & Tech Inspiration
Cowboy | eCommerce Website Design Gallery & Tech Inspiration

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

Teslica eBikes | Ottawa eBike Store | Canada Wide Shipping
Teslica eBikes | Ottawa eBike Store | Canada Wide Shipping

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

Cycloner - bicycle Website
Cycloner - bicycle Website
Basic Guide to Creating a Page Using Velo by Wix
Basic Guide to Creating a Page Using Velo by Wix
a bike parked on the side of a street next to a wall with an orange line
a bike parked on the side of a street next to a wall with an orange line
a man riding on the back of a yellow bike
a man riding on the back of a yellow bike
Новые и клевые: 15 шаблонов на все случаи жизни | Блог Wix
Новые и клевые: 15 шаблонов на все случаи жизни | Блог Wix
Oh My Bike! - Crafted Pixels
Oh My Bike! - Crafted Pixels
a man riding a bike on top of a metal platform with green dots around it
a man riding a bike on top of a metal platform with green dots around it
a man riding a bike on top of a road
a man riding a bike on top of a road
an orange bike is displayed on the website
an orange bike is displayed on the website

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!