All Products
Search
Document Center

Mobile Platform as a Service:How to put parameters in the post body

Last Updated:Feb 02, 2024

The HTML5 application needs to call the MGS API through JSAPI. The MGS API is a POST API in the business system. No instructions on how to construct a POST request on the HTML5 are available for users.

Problem description

The HTML5 application needs to call the MGS API through JSAPI. The MGS API is a POST API in the business system. No instructions on how to construct a POST request on the HTML5 are available for users.

Server-side configuration

Description of business-side API

Suppose the business-side API is described as follows:

POST /api/product
{
  "id": 0,
  "productName": "Mask"
}

The POST Body must contain two parameters id and productName for the API to receive a POST request.

Data model configuration

Create a data model for POST Body according to the API description.

Log in to the mPaaS console, go to the Mobile Gateway Service > Data model page, click Create data model to add the data model, and then construct the data model according to the description.

Configure gateway API

Go to the Mobile Gateway Service > Manage API > Create API page, and complete the following operations:

  1. Modify API basic information as needed.

  2. Configure the request parameters. The request Body is the data model defined in above step, and the return value and message type can be configured as required.

HTML5-side call

When you send a request via JSAPI, the contents of the POST Body need to be placed in the requestData parameter as the value of _requestBody, see the following example:

window.AlipayJSBridge.call('rpc', {
         operationType: 'com.mpaas.addProduct',
         requestData: [
         {"_requestBody":"{\"id\":\"1\",\"name\":\"mask\"}"}],
         headers:{},
         getResponse: true
       }, function(data) {
         alert(JSON.stringify(data));
       });