Hello Web Modules

Allows you to define and call backend functions from the frontend.

Introduction Last updated: 10 Mar 2025

About


In this example, we use web modules to define and export web methods. Web methods wrap backend functions which allows them to be called asynchronously from the frontend and adds a permissions check on the caller of your function.

APIs


How we built it


We added the following to our site:

Page Elements

Simple
  • A button to call the web method.
  • A text element to display the web method's response.
Permissions
  • 3 buttons to call different web methods. Each web method requires different permissions.
  • 2 text elements to display the called web method's response and error. These text elements are never shown at the same time.
  • A login bar for site visitors to log in to the site.

Frontend Code

Simple

The code in this file enables site visitors to call a web method that sends a greeting as a response. In this file, we:

  1. Defined a call count. 

  2. Added an onClick event handler to the Call backend function button that:

    1. Calls a web method to retrieve a random greeting, specifying the call count.

    2. Increments the call count by 1.

    3. Displays the web method's response. 

Permissions

The code in this file enables site visitors to call 1 of 3 web methods that sends a greeting as a response. Each web method requires different permissions.

In this file, we added an onClick event handler to each button that:

  1. Calls a web method. Each button calls a web method with different permissions.

  2. If the site visitor has the required permissions, the site displays the web method's response.

  3. If the call to the web method fails, the site displays an error message.

Code Snippets


helloModule.web.js
Copy
Simple
Copy
Permissions
Copy

Get Help


Join the community

Join the Wix Studio community on Discord, where experienced developers and fellow creators come together to share tips, troubleshoot issues, and collaborate.

Hire a developer

Building a coded solution on your own can be challenging. Let an experienced Wix developer build it for you, so you can keep working on your site or business. Visit the Wix Marketplace to find a trusted developer.

Did this help?