webMethod( )
Defines a backend function that can be called from the frontend.
The webMethod()
function is a wrapper used to export functions from backend code that can be called from the frontend.
The permissions
parameter is used to define the permissions needed to call the function in frontend code. 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.
The cache
object, found in the options
parameter, enables you to cache or temporarily store the return values of your backend functions for a specific duration. Use the ttl
property to define the duration, in seconds, for which you want your return value to be cached. If the Time To Live (TTL) is not set, the default value is 604000
seconds, which is approximately 1 week.
You can also assign identifiers to cached return values using the tags
property of the cache
object. Tags allow you to specify cached return values that may require invalidation due to a significant change in your data. To invalidate a cached return value, use the invalidateCache()
function from wix-cache-backend
. Once invalidated, the return value will be re-cached the next time the function is called.
Important:
If you plan to invalidate your caches, you must first cache them using the tags
property to identify them. Without tags, your cache will only be invalidated when the TTL expires or when you republish your site with a code change.
Web methods must be defined in files with a .web.js
extension.
Permissions needed to call the function in frontend code.
Function to export.
Caching options.