Construct Request
This document presents the construction method of the Baidu AI Cloud REST API request. The information presented in this document can be obtained from the API3.0 documentation. You can also learn more about how to construct an API request through Video Guide.
Request URI
The request URI structure is as follows:
{Protocol}://{Access domain name}/{Request path}?{Request query}
Parameters | Description | Example |
---|---|---|
Protocol | Type of protocol for transmitting the request. It can be HTTP and HTTPS protocols, and HTTPS is recommended. | HTTPS |
Access domain name | It refers to the domain name or IP that provides the cloud product API service. Different products have different Endpoints. Refer to [BOS Access Domain Name](https://cloud.baidu.com/doc/BOS/s/Ck1rk80hn#Access Domain Name (endpoint)) | bj.bcebos.com |
Request path | API access path, which is generally used to point to the path of resources. | v2/instance |
Request query | Query parameters, which follows “?”. Not all interfaces have the query request, which needs to be judged according to the API documentation. | reboot |
For example, if you want to call the Restart Instance API of BCC, the request URI is as follows:
Because the protocol and access domain name are relatively fixed in the specific API documentation, they are omitted for simplicity, and the API request method is placed before the request path as shown below:
Request Message Header
The request message header carries some public configuration information, such as the data type of the message body, call initiation time, and authentication information. The request message headers that can be used by all APIs are called public request message headers, which are listed in the table below.
Name | Type | Description | Required? |
---|---|---|---|
Authorization | String | It is the authentication information used to verify the validity of the request. For more details, see Authentication. | Yes |
Content-Length | String | Length of the HTTP request content defined in RFC2616 | No |
Content-Type | String | Type of the HTTP request content defined in RFC2616, which is usually application/json; charset=utf-8. | No |
Content-MD5 | String | The MD5 digest of the HTTP request content defined in RFC2616, which can be contained to verify whether the file saved in BOS is consistent with the user's expected file. | No |
Date | String | GMT time specified in the HTTP 1.1 protocol, such asWed, 06 Apr 2016 06:34:40 GMT . |
No |
Host | String | Access host value, whose value is BucketName.bj.baidubce.com . |
Yes |
x-bce-date | String | Current time, which conforms to the ISO8601 specification in the following format: 2016-04-06T08:23:49Z . |
No |
If an API has its request message header, it is stated in the API documentation.
Request Message Body
The data structure in the request message body is defined by Content-Type in the request message header. In most cases, the JSON format is required.
The request message body of each API has different contents, and not all interfaces require the request message body (or the message body is empty). In general, the message body is required for API of GET and DELETE operations. For the specific message body, see the API documentation.
In the API documentation, the Description of Data Structure for Request Body Field is the field information on the outermost layer of the request message body JSON. If this API has no request message body, this part is empty.
If the request message body JSON contains the nested data structure, it is displayed with the Description of Data Structure for Certain Field under the table of Data Structure Description of Request Body Field.