Search...
webMethod( )
Defines a backend function that can be called from the frontend.
Description
The webMethod()
function is a wrapper used to export functions from backend code that can be called from the frontend.
Use the function's first parameter to define the permissions needed to call the function in frontend code. You can import
the Permissions
enum from the wix-web-module
module to define the permissions.
The permission options are:
Permissions.Anyone
: Any site visitor can call the function.Permissions.Admin
: Only site admins can call the function.Permissions.SiteMember
: Only site members can call the function.
Web methods must be defined in files with a .web.js
extension.
Authorization
Request
This endpoint does not take any parameters
Response Object
Returns an empty object.
Status/Error Codes
Was this helpful?
Export a backend function and use it in frontend code
Copy Code
1// Exporting a backend function from a '.web.js' file:2import {Permissions, webMethod} from "wix-web-module";34export const multiply = webMethod(Permissions.Anyone, (a,b) => a * b);56// Using the function in frontend code:7import {multiply} from "backend/multiply.web";89$w.onReady(async function () {10 multiply(5, 3).then((result) => {11 console.log(result); // Logs 1512 });13});