All Products
Search
Document Center

How to put parameters in the post body

Last Updated: Apr 08, 2021

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:

 
  1. POST /api/product
  2. {
  3. "id": 0,
  4. "productName": "Mask"
  5. }

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:

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