Main Content

POST Synchronous Request

Make synchronous request to MATLAB REST function service and wait for response

Since R2024a

Description

Use a POST method to make a synchronous request to a MATLAB® REST function service.

Uses JSON as the data serialization format.

Request

HTTP Method

POST

URI

https://<hostname>:<port>/matlab/feval/v1/<matlabFunctionName>

Query Parameters

None.

Content-Type

  • application/json

Body

NameDescriptionValue-Type
nargout

Number of outputs that the client application is requesting from the MATLAB function. Note that MATLAB functions, depending on their intended purpose, can be coded to return multiple outputs. A subset of these potential outputs can be specified using nargout.

number
rhs

Input arguments to the MATLAB function, specified as an array of comma-separated values.

[arg1,arg2,arg3,...]
outputFormat

Specify whether the MATLAB output in the response should be returned using large or small JSON notation, and whether NaN and Inf should be represented as a JSON string or object. If the mode is not specified or the returned MATLAB data type does not support JSON small notation, the response is represented using JSON large notation.

For more information on the JSON representation of MATLAB data types, see JSON Representation of MATLAB Data Types (MATLAB Production Server).

{ "mode" : "small | large", "nanInfFormat" : "string | object" }

Response

Success

Body

NameDescriptionValue-Type
lhs

A JSON array contained in the response from the server. Each element of the JSON array corresponds to an output of the MATLAB function represented using JSON notation. For more information on JSON notation see JSON Representation of MATLAB Data Types.

[output1, output2, ...]

Error

Standard HTTP status codes.

Sample Call

HTTP

This example shows how to create a POST request to call res = mySqrt(25) using this MATLAB function.

function result = mySqrt(x)
    result = sqrt(x);
end

Request:

POST /matlab/feval/v1/TestService/mySqrt HTTP/1.1
Host: localhost:9920
mwRESTPersonalAccessToken: VAAKeo/2MaCzb72rMv1TX0df/HbjSSL47kWy5B694BE=
Content-Type: application/json
Content-Length: 80

{"rhs":[25.0], "nargout":1, "outputFormat":{"mode":"small", "nanType":"string"}}

For more information about this example, see Call User-Defined Function with MATLAB REST Function Services.

Version History

Introduced in R2024a