# Getting Started with Velo by Wix

Source: https://support.wix.com/en/article/getting-started-with-velo-by-wix (updated 2024-06-04)
Related: Wix developer documentation, https://dev.wix.com/docs/llms.txt; Help Center index, https://support.wix.com/en/llms.txt

Visit the [Velo by Wix website](https://www.wix.com/velo) to onboard and continue learning.

Velo by Wix is an innovative product that lets you build robust web applications with zero setup. Work in Wix's visual builder, add custom functionality and interactions using Velo APIs, and enjoy serverless coding in both the front-end and backend. With Velo, your web app can be up and running in a fraction of the time it would normally take you.

To introduce you to Velo, we created our own version of a "Hello, World!" example: a simple currency converter site that uses the [wix-fetch API](https://www.wix.com/velo/reference/wix-fetch.html) to connect to a 3rd-party service. Site visitors choose source and target currencies from dropdowns and enter an amount to convert. The results are displayed in a text box.

![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/0ca9e8ba-16ed-4cd8-a1e1-58d01c4420f7/2019/03/07/37a87ea6-7a20-4902-b51a-0fe6acecd54a.png)

Follow the steps below to get familiar with the basic structure and syntax of Velo.

## Step 1: Create a New Wix Site

1. Sign into your Wix account or [sign up for a Wix account](https://users.wix.com/signin?overrideLocale=en&loginDialogContext=signup) if you don’t already have one.
2. [Open a blank template](https://editor.wix.com/html/editor/web/renderer/new?siteId=cbf36d3a-49d0-41c2-9482-1bb58d5fdda3&metaSiteId=a573279f-ae6f-46d1-8556-7c93ae9b2c84&editorSessionId=799795e9-07c2-4e7e-8a17-33dab829f776) in the Editor.

## Step 2: Enable Velo Dev Mode

Click **Dev Mode** in your site's top bar and turn on **Enable Developer Mode** in the dropdown.

  
![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/703598e8-0a86-4968-a251-e6562cdf4684/2022/12/20/b664427d-1ca1-4629-9430-e5a1ac97fd97/90204ee2-89d6-4a18-b6d4-9ab2542e1363.png)

## Step 3: Add Elements to the Page

Add page elements in the Wix Editor:

1. On the left side of the Editor, click **Add**.
2. Add the page elements illustrated below to your site.  
   * When you add each element, set its ID in the [Properties & Events](https://support.wix.com/en/article/velo-working-with-the-properties-events-panel) panel that appears on the right side of the Code Panel. Use the name shown below for each element, minus the hashtag. See the table below for a full list of the elements and where to find them in the Add menu.

![](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/11e10e4f-b84d-4136-a5a9-6109fab0b7d7/2020/10/25/0cb6d2f8-071b-4f56-90a6-f307dcae7c5f/11c3401f-811c-4a02-8c62-e89ccb83a983.png)

| Element | Location in Add Menu | Description | ID |
| --- | --- | --- | --- |
| Dropdown | User Input | For selecting the source currency | sourceCurrency |
| Dropdown | User Input | For selecting the target currency | targetCurrency |
| Input | User Input | For entering the amount to convert | sourceAmount |
| Text Box | User Input | To display the converted amount | targetAmount |
| Button | Button | To trigger the currency conversion when clicked | calculateButton |

## Step 4: Add Code

> **Notes**
>
> * All the code for this example is added to a single page on the site. In this section we divided the code into short blocks followed by explanations. To see the complete code for this example without comments, [scroll down](https://support.wix.com/en/article/getting-started-with-velo-by-wix#example-code) to the end of the tutorial.
> * See our [API Reference](https://www.wix.com/velo/reference/) to learn more about the Velo-based code in this example.

**To add the code:**

1. Double-click **Home Page Code** at the bottom of the Editor to open the [Code Panel](https://support.wix.com/en/article/velo-working-in-the-code-panel).
2. Add the following code to the top of the code in the tab before the [onReady](https://support.wix.com/en/article/velo-working-in-the-code-panel#making-sure-the-element-has-loaded-before-you-reference-it) function:

```javascript
// The getJSON function in wix-fetch lets you retrieve a
// JSON resource from the network using HTTPS.
import {getJSON} from 'wix-fetch';

// Set the URL of the 3rd-party service.
const url = "https://api.exchangerate.host/convert";

// Define the currency option values and text for the dropdowns.
let currencyOptions = [
  { "value": "USD",  "label": "US Dollars"},
  { "value": "EUR",  "label": "Euros"},
  { "value": "JPY",  "label": "Japanese Yen"},
];
```

1. Add the code below to the [onReady](https://support.wix.com/en/article/velo-working-in-the-code-panel#making-sure-the-element-has-loaded-before-you-reference-it) function. Code inside the onReady function runs when the page loads.

```javascript
$w.onReady(function () {
  // Set the currency options for the dropdowns.
  populateDropdowns();

  // Set the onClick event handler for calculateButton to calculate the target amount.
  $w('#calculateButton').onClick((event) => {
    calculateCurrency();
  })
});
```

The [$w](https://www.wix.com/code/reference/$w.html#$w) function can select elements on a page by ID or by type, allowing us to run functions and define the properties of the elements. Use this syntax to select an element by ID, `$w("#myElementId")`, and this syntax to select by type, `$w("ElementType")`.

Here we select the button and define an `onClick` [event handler](https://support.wix.com/en/article/velo-reacting-to-user-actions-using-events#about-events-event-handlers-and-wiring) to calculate the target amount.

4\. Add code to define the functions:  
  
**populateDropdowns( )**

```javascript
// Populate the dropdowns.
function populateDropdowns(){
  //Set the dropdown options.
  $w("Dropdown").options = currencyOptions;
  // Set the first dropdown option as the initial option.
  $w("Dropdown").selectedIndex = 0;
}
```

Here we select all the dropdowns by type. By calling [$w](https://www.wix.com/velo/reference/$w.html) with the element type "Dropdown", we select all dropdowns on the page.

**calculateCurrency( )**

```javascript
// Calculate the target amount.
function calculateCurrency() {
  // Initial amount 
  let initialAmount = $w("#sourceAmount").value;
  // Original currency
  let sourceSymbol = $w("#sourceCurrency").value;
  // Target currency
  let targetSymbol = $w("#targetCurrency").value;
  // Define the full url.
  let fullUrl = `${url}?from=${sourceSymbol}&to=${targetSymbol}`;
    
  // Call the wix-fetch API function to retrieve the JSON resource.
  getJSON(fullUrl)
  .then(json => {
    // Set the target amount as the initial amount multiplied by
    // the conversion rate.
    $w("#targetAmount").value = initialAmount * json.info.rate;
  }
)}
```

We use [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template%5Fliterals) to define the full URL, which includes the source and target currencies.

The wix-fetch API [getJSON](https://www.wix.com/velo/reference/wix-fetch.html#getJSON) function retrieves the JSON resource using the full URL. `getJSON` returns a [promise](https://support.wix.com/en/article/velo-working-with-promises), which resolves to a JSON object.

We multiply the retrieved rate by the initial amount and assign it to the `targetAmount` text box.

## Step 5: See It in Action

Now it's time to test your site:

1. Click **Preview** at the top right of the Editor.
2. Enter an amount in the source currency input.
3. Click the calculate button and see the converted currency result in the target amount text box.
4. [Publish](https://support.wix.com/en/article/wix-editor-publishing-your-site) your site to make it live and production ready.

 That's it! In just a few minutes, you created a web application in Velo! No setup, no managing server infrastructure, just integrating Velo APIs with the Wix visual builder.

## Next Steps

Now that you've had a taste of Velo, check out what else you can do:

* Easily call backend code from the frontend using [web modules](https://support.wix.com/en/article/velo-web-modules-calling-backend-code-from-the-frontend).
* Work with Wix's [visual builder](https://support.wix.com/en/article/wix-editor-getting-started-with-the-wix-editor).
* Add features and customize your site using [Velo APIs](https://www.wix.com/velo/reference/api-overview/introduction). Here are some examples of what you can do:  
   * [Collect](https://support.wix.com/en/article/velo-tutorial-using-the-velo-pay-api-to-collect-payments-for-a-single-product) payments  
   * [Create](https://support.wix.com/en/article/velo-tutorial-expand-text-with-a-read-more-link) a show-more link  
   * [Use](https://www.wix.com/velo/example/create-a-custom-chart) an HTML component to embed a chart on your page  
   * Work with the data from [other Wix Apps](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections) like [Stores](https://support.wix.com/en/velo-by-wix/wix-stores-with-velo), [Bookings](https://support.wix.com/en/velo-by-wix/wix-bookings-with-velo), and [Events](https://support.wix.com/en/velo-by-wix/wix-events-with-velo)
* Visit the [Velo by Wix website](https://www.wix.com/velo) to onboard and continue learning. Check out Velo [documentation](https://support.wix.com/en/velo-by-wix/basics) and the [API Reference](https://www.wix.com/velo/reference).

## Example Code

Here is the complete code for this example, without comments:

```javascript
import {getJSON} from 'wix-fetch';

const url = "https://api.exchangerate.host/convert";

let currencyOptions = [
  { "value": "USD",  "label": "US Dollars"},
  { "value": "EUR",  "label": "Euros"},
  { "value": "JPY",  "label": "Japanese Yen"},
];

$w.onReady(function () {
  populateDropdowns();
 
  $w('#calculateButton').onClick((event) => {
    calculateCurrency();
  })
});

function populateDropdowns(){
  $w('Dropdown').options = currencyOptions;
  $w('Dropdown').selectedIndex = 0;
}

function calculateCurrency() {
  let initialAmount = $w("#sourceAmount").value;
  let sourceSymbol = $w("#sourceCurrency").value;
  let targetSymbol = $w("#targetCurrency").value;
  let fullUrl = `${url}?from=${sourceSymbol}&to=${targetSymbol}`;

  getJSON(fullUrl)
  .then(json => {
    $w("#targetAmount").value = initialAmount * json.info.rate;
  }
)}
```
