Make an asynchronous request to the server
Use a POST method to make an asynchronous request to the server. During asynchronous execution, this step is usually the first in the process.
POST
http://host:port/deployedArchiveName/matlabFunctionName
Name | Description | Value-Type |
---|---|---|
mode | (Required). Specify mode of communication. |
|
client | (Optional). Specify an ID or name for the client making the request. |
|
Example:
?mode=async&client=Nor101
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 weather 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" } }
201 Created
Name | Description | Value-Type |
---|---|---|
id | ID of a particular request. | {id-string} |
self | URI of particular request. | {request-uri-string} |
up | URI of a collection of requests tied to a particular client. | {request-collection-uri-string} |
lastModifiedSeq | Number indicating when a request represented by self was
last modified. | {server-state-number} |
state | State of a request. | {request-state-string} List of states: READING IN_QUEUE PROCESSING READY ERROR CANCELLED |
client | Client id/name that was specified as a query parameter while initiating a request. | {client-id-string} |
Example:
{ "id": "a061c723-4724-42a0-b405-329cb8c373d6", "self": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/a061c723-4724-42a0-b405-329cb8c373d6", "up": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests", "lastModifiedSeq": 6, "state": "READING", "client": "" } |
404 ResourceNotFound
405 MethodNotAllowed
— No 'Access-Control-Allow-Origin'
header.
Enable CORS on server.
415 InvalidContentType
415 UnsupportedMediaType
Request: POST /mymagic/mymagic?mode=async HTTP/1.1 Host: localhost:9910 Content-Type: application/json {"rhs":[7],"nargout":1,"outputFormat":{"mode":"small","nanType":"string"}} Response: Status Code: 201 Created Header: Location: /~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/ad2363f3-26c1-4d48-88f8-6b7fb615f254 X-MPS-Start-Time: 003472d705bd1cd2 Content-Length: 248 Body: { "id": "ad2363f3-26c1-4d48-88f8-6b7fb615f254", "self": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests/ad2363f3-26c1-4d48-88f8-6b7fb615f254", "up": "/~e4a954fd-5eaf-4b54-aac2-20681b33d075/requests", "lastModifiedSeq": 41, "state": "READING", "client": "786" } |
var data = JSON.stringify( { "rhs": [7], "nargout": 1, "outputFormat": {"mode": "small","nanType": "string"} } ); var xhr = new XMLHttpRequest(); xhr.open("POST", "http://localhost:9910/mymagic/mymagic?mode=async"); xhr.setRequestHeader("content-type", "application/json"); xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.send(data); |