POST Asynchronous Request
Make asynchronous request to server
Description
Use a POST method to make an asynchronous request to the server. During asynchronous execution, this step is usually the first in the process.
The following sections use JSON as the data serialization format. For an example that shows how to use protobuf as the data serialization format with the Java® client API and the .NET client API, see Asynchronous RESTful Requests Using Protocol Buffers in the Java Client and Asynchronous RESTful Requests Using Protocol Buffers in .NET Client.
Request
HTTP Method
POST
URI
http://host:port/deployedArchiveName/matlabFunctionName
Query Parameters
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
Content-Type
application/json
Body
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. You can
use | 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 notation, and whether
For more information on the JSON representation of MATLAB data types, see JSON Representation of MATLAB Data Types. | { "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" } }
Response
Success
201 Created
Name | Description | Value-Type |
---|---|---|
id | ID of a particular request. | {id-string} |
self | URI of particular request. Use the URI in other asynchronous execution requests such as retrieving the state of the request or result of request. | {request-uri-string} |
up | URI used to view a collection of requests on the server. For more details, see GET Collection of Requests. | {request-collection-uri-string} |
lastModifiedSeq | Number indicating when a request represented by self was
last modified. | {server-state-number} |
state | State of a request. |
List of states: READING IN_QUEUE PROCESSING READY ERROR CANCELLED |
client | Client id or 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": "" } |
Error
404 ResourceNotFound
405 MethodNotAllowed
— No 'Access-Control-Allow-Origin'
header.
Enable CORS on server.
415 InvalidContentType
415 UnsupportedMediaType
Sample Call
HTTP
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": "" } |
JavaScript
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); |
Version History
Introduced in R2016b
See Also
GET Representation of Asynchronous Request | POST Cancel Request | DELETE Request
Topics
- Asynchronous Execution
- Example: Asynchronous Execution of Magic Square Using RESTful API and JSON
- Create Web-Based Tool Using RESTful API, JSON, and JavaScript
- Asynchronous RESTful Requests Using Protocol Buffers in .NET Client
- Asynchronous RESTful Requests Using Protocol Buffers in the Java Client
- JSON Representation of MATLAB Data Types