Skip to content

FunctionProvider Service Documentation

The FunctionProvider service allows executing server-side functions from the client. It provides a simple interface to run named functions with arguments and receive the result.

TIP

To learn how to define functions on the server, check out the Server-side Functions documentation.

To use the FunctionProvider service, import it as follows:

javascript
import { functionProvider } from '@modular-rest/client'

run()

Executes a server-side function.

Arguments

NameTypeDescription
options{ name: string; args: any }Object containing function name and arguments

Return and Throw

TypeDescription
Promise<any>Resolves with the result returned by the server-side function
ErrorThrows an error if the function execution fails or returns an error

Example

javascript
const options = {
  name: 'calculateSum',
  args: { a: 10, b: 20 }
};

functionProvider.run(options)
  .then(result => console.log('Function result:', result))
  .catch(error => console.error('Function execution failed:', error));