Main Content


Service for calling MATLAB functions from client applications

Since R2024a


    To execute a function within a specific MATLAB® session from a client application, create a RESTFunctionService object in the MATLAB session. When you call start on this object, it registers a service with a RESTFunctionConnector object, so that it can receive client requests. You can create multiple services in the same MATLAB session or services in different MATLAB sessions.

    If you want to change your token, certificate, or port, or start a remote connection, use a RESTFunctionConnector object.




    service = restFunctionService(Name,FcnList) creates a service in MATLAB so that a client application can call the functions in FcnList using the service name Name.

    service = restFunctionService(Name,FcnList,ClientAccessMode) specifies the access mode.


    expand all

    Service name, specified as a string scalar or character vector. Because the service provides access across all MATLAB sessions, its name must be unique. The name must also be a valid MATLAB variable name.

    Example: "M1"

    List of user-defined MATLAB functions, classes, or scripts, specified as a string vector. Your client application calls these functions from the MATLAB session. To register these functions, call start.

    Example: ["myMagic","myAdd"]

    Access mode, specified as "local" or "remote".

    Example: ClientAccessMode="remote"

    This property is read-only.

    Required artifacts that the client application needs to make requests to the service, returned as a ClientRequestInfo object.

    This property is read-only.

    REST function connector, returned as the existing underlying RESTFunctionConnector object.

    This property is read-only.

    Service status, returned as notrunning or running. The property indicates whether the service is running and can receive client requests.

    Object Functions

    startStart REST function service from MATLAB


    collapse all

    Create a service named EL to provide local clients access to your functions myAdd, myMagic, and mySub.

    serviceL = restFunctionService("EL",["myAdd" "myMagic" "mySub"])
    serviceL =  
        RESTFunctionService with properties: 
                       Name: "EL"  
                  Functions: ["myAdd" "myMagic" "mySub"] 
           ClientAccessMode: local 
          ClientRequestInfo: [1x0 ClientRequestInfo]    
          FunctionConnector: [1x1 RESTFunctionConnector] 
                     Status: notrunning

    Start the service.

    info = serviceL.start

    Set up a call from your client program using data in the ClientRequestInfo info. For more information, see Call User-Defined Function with MATLAB REST Function Services.

    Version History

    Introduced in R2024a