Make a synchronous request to the server, and wait for a response
Use a POST method to make a synchronous request to the server. In synchronous mode, once a request has been made, the server blocks all further requests until it has completed processing the original request. A response is automatically returned once processing is complete. No other HTTP methods are necessary to retrieve the response from the server.
POST
http://host:port/deployedArchiveName/matlabFunctionName
None.
application/json
| Name | Description | Value-Type |
|---|---|---|
nargout | Number of outputs that the client application is requesting
from the deployed 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 | number |
rhs | Input arguments to the deployed 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 representation, and whether | { "mode" : "small | large", "nanInfFormat"
: "string | object" } |
Example:
Single Input Argument:
{
"nargout": 1,
"rhs": [5],
"outputFormat" : { "mode" : "small","nanInfFormat": "object"}
}{
"nargout": 2,
"rhs": [3, 4, 5 ...],
"outputFormat" : { "mode" : large", "nanInfFormat" : "string" }
}200 OK
| Name | Description | Value-Type |
|---|---|---|
lhs | A JSON |
|
Example:
{
"lhs":[[[17,24,1,8,15],[23,5,7,14,16],[4,6,13,20,22],[10,12,19,21,3],[11,18,25,2,9]]]
} |
400 InvalidJSON
404 FunctionNotFound
404 ComponentNotFound
Request: POST /mymagic/mymagic HTTP/1.1
Host: localhost:9910
Content-Type: application/json
{"rhs":[5],"nargout":1,"outputFormat":{"mode":"small","nanType":"string"}}Response: Status Code: 200 OK
{
"lhs":[[[17,24,1,8,15],[23,5,7,14,16],[4,6,13,20,22],[10,12,19,21,3],[11,18,25,2,9]]]
} |
var data = JSON.stringify({
"rhs": [5],
"nargout": 1,
"outputFormat": {"mode": "small", "nanType": "string"}
});
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "http://localhost:9910/mymagic/mymagic");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data); |