Note: The Web Methods API is currently only supported for building apps using the Wix CLI. For developing sites, use the Velo Web Modules API.
The Web Methods API allows you to define functions in your backend code that you can call from your app's frontend code. You can also define the permissions required to call the function. You can define these functions in web method extensions.
Web methods provide several advantages over using http functions to call your app's backend.
To use the Web Methods API, install the @wix/code
package:
or
Then import the webMethods
utility and Permissions
enum from @wix/code/web-methods
:
The Permissions
enum is used to define the permissions needed to call the function in frontend code. See the webMethod()
documentation for more details.
Web methods are defined in your backend code using the webMethod()
wrapper function, then imported into and called from your frontend code.
Web methods must be defined in a file with a .web.ts
extension.
Note: The passed function can be asynchronous, and must return serializable results.
Import the web method, then call it. For example: