forked from laiweijian4/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Chen, Junjie <chenjunjie@huawei.com> Co-committed-by: Chen, Junjie <chenjunjie@huawei.com>
77 lines
12 KiB
HTML
77 lines
12 KiB
HTML
<a name="apig-en-api-180713011"></a><a name="apig-en-api-180713011"></a>
|
|
|
|
<h1 class="topictitle1">Making an API Request</h1>
|
|
<div id="body54158540"><p id="apig-en-api-180713011__p49031951191414">This section describes the structure of a REST API request, and uses the APIG API for creating an API group (dedicated gateways) as an example to demonstrate how to call an API.</p>
|
|
<div class="section" id="apig-en-api-180713011__section1849899574"><h4 class="sectiontitle">Request URI</h4><p id="apig-en-api-180713011__p729531715312">A request URI is in the following format:</p>
|
|
<p id="apig-en-api-180713011__p11610193811547"><strong id="apig-en-api-180713011__b3129104565416">{URI-scheme} :// {<strong id="apig-en-api-180713011__b10231116812">Endpoint</strong>} / {resource-path} ? {query-string}</strong></p>
|
|
<p id="apig-en-api-180713011__p19153141415558">Although a request URI is included in the request header, most programming languages or frameworks require the request URI to be transmitted separately.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="apig-en-api-180713011__table15493243134713" frame="border" border="1" rules="all"><caption><b>Table 1 </b>URI parameters</caption><thead align="left"><tr id="apig-en-api-180713011__row458213435474"><th align="left" class="cellrowborder" valign="top" width="25.89%" id="mcps1.3.2.5.2.3.1.1"><p id="apig-en-api-180713011__p17583184311478">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="74.11%" id="mcps1.3.2.5.2.3.1.2"><p id="apig-en-api-180713011__p75831443184713">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="apig-en-api-180713011__row125831543184710"><td class="cellrowborder" valign="top" width="25.89%" headers="mcps1.3.2.5.2.3.1.1 "><p id="apig-en-api-180713011__p6583194310473">URI-scheme</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="74.11%" headers="mcps1.3.2.5.2.3.1.2 "><p id="apig-en-api-180713011__p15832043194714">Protocol used to transmit requests. All APIs use HTTPS.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="apig-en-api-180713011__row5583184319479"><td class="cellrowborder" valign="top" width="25.89%" headers="mcps1.3.2.5.2.3.1.1 "><p id="apig-en-api-180713011__p858374313475">Endpoint</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="74.11%" headers="mcps1.3.2.5.2.3.1.2 "><p id="apig-en-api-180713011__p17583104310471">Domain name or IP address of the server bearing the REST service. The endpoint varies between services in different regions. It can be obtained from <a href="apig-api-190529265.html">Endpoints</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="apig-en-api-180713011__row20583643174717"><td class="cellrowborder" valign="top" width="25.89%" headers="mcps1.3.2.5.2.3.1.1 "><p id="apig-en-api-180713011__p15583174314476">resource-path</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="74.11%" headers="mcps1.3.2.5.2.3.1.2 "><p id="apig-en-api-180713011__p1858315433471">Access path of an API for performing a specified operation. Obtain the path from the URI of an API. For example, the <strong id="apig-en-api-180713011__b13288823171018">resource-path</strong> of the API used to create an API group is <strong id="apig-en-api-180713011__b128862310102">/v2/</strong><em id="apig-en-api-180713011__i1289132319102">{project_id}</em><strong id="apig-en-api-180713011__b1028922331010">/apigw/instances/</strong><em id="apig-en-api-180713011__i10289123111015">{instance_id}</em><strong id="apig-en-api-180713011__b152899231106">/api-groups</strong>. <em id="apig-en-api-180713011__i1328918231104">{project_id}</em> indicates a <a href="apig-en-api-180713009.html">project ID</a> and <em id="apig-en-api-180713011__i13289192310107">{instance_id}</em> indicates a gateway ID. The two IDs can be obtained from the gateway information on the APIG console.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="apig-en-api-180713011__row2583134315471"><td class="cellrowborder" valign="top" width="25.89%" headers="mcps1.3.2.5.2.3.1.1 "><p id="apig-en-api-180713011__p155831243184718">query-string</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="74.11%" headers="mcps1.3.2.5.2.3.1.2 "><p id="apig-en-api-180713011__p158364315474">Query parameter, which is optional. Ensure that a question mark (?) is included before each query parameter that is in the format of "<em id="apig-en-api-180713011__i49635134718">Parameter name</em>=<em id="apig-en-api-180713011__i44326864713">Parameter value</em>". For example, <strong id="apig-en-api-180713011__b19477450134611">?limit=10</strong> indicates that a maximum of 10 data records will be displayed. Separate multiple query parameters with ampersands (&).</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="apig-en-api-180713011__p1766380168">For example, to create an API group in a region, combine the parameters in the URI. <em id="apig-en-api-180713011__i3211736154920">apig_endpoint</em> indicates the endpoint of APIG.</p>
|
|
<pre class="screen" id="apig-en-api-180713011__screen439264613101">https://{apig_endpoint}/v2/{project_id}/apigw/instances/{instance_id}/api-groups</pre>
|
|
<div class="note" id="apig-en-api-180713011__note16311253154112"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="apig-en-api-180713011__p163316534416">To simplify the URI display in this document, each API is provided only with a <strong id="apig-en-api-180713011__b104237521597">resource-path</strong> and a request method. The <strong id="apig-en-api-180713011__b7323146107">URI-scheme</strong> of all APIs is <strong id="apig-en-api-180713011__b5411119141013">HTTPS</strong>, and the endpoints of all APIs in the same region are identical.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="apig-en-api-180713011__section580035055419"><h4 class="sectiontitle">Request Methods</h4><p id="apig-en-api-180713011__p65661618145510">The HTTP protocol defines the following request methods that can be used to send a request to the server:</p>
|
|
<ul id="apig-en-api-180713011__ul11356238151312"><li id="apig-en-api-180713011__li1835819385137"><strong id="apig-en-api-180713011__b1982261181919">GET</strong>: requests the server to return specified resources.</li><li id="apig-en-api-180713011__li95631239131310"><strong id="apig-en-api-180713011__b1643311619198">PUT</strong>: requests the server to update specified resources.</li><li id="apig-en-api-180713011__li1554910413138"><strong id="apig-en-api-180713011__b885128131910">POST</strong>: requests the server to add resources or perform special operations.</li><li id="apig-en-api-180713011__li8237114421314"><strong id="apig-en-api-180713011__b35991114196">DELETE</strong>: requests the server to delete specified resources, for example, an object.</li><li id="apig-en-api-180713011__li165331349151317"><strong id="apig-en-api-180713011__b463012126195">HEAD</strong>: same as GET except that the server must return only the response header.</li><li id="apig-en-api-180713011__li4440175411313"><strong id="apig-en-api-180713011__b201891160194">PATCH</strong>: requests the server to update partial content of a specified resource. If the resource does not exist, a new resource will be created.</li></ul>
|
|
<p id="apig-en-api-180713011__p3759142614815">For example, in the case of the API used to create an API group (dedicated gateways), the request method is POST. The request is as follows:</p>
|
|
<pre class="screen" id="apig-en-api-180713011__screen9521132712346">POST https://{apig_endpoint}/v2/{project_id}/apigw/instances/{instance_id}/api-groups</pre>
|
|
</div>
|
|
<div class="section" id="apig-en-api-180713011__section1454211155819"><h4 class="sectiontitle">Request Header</h4><p id="apig-en-api-180713011__p11811752397">You can also add additional header fields to a request, such as the fields required by a specified URI or HTTP method. For example, to request for the authentication information, add <strong id="apig-en-api-180713011__b207441711171213">Content-Type</strong>, which specifies the request body type.</p>
|
|
<p id="apig-en-api-180713011__p1467193205816">Common request header fields are as follows:</p>
|
|
<ul id="apig-en-api-180713011__ul157293410593"><li id="apig-en-api-180713011__li972916419595"><strong id="apig-en-api-180713011__b1730195832019">Content-Type</strong>: specifies the request body type or format. This field is mandatory and its default value is <strong id="apig-en-api-180713011__b14472204231215">application/json</strong>. Other values of this field will be provided for specific APIs if any.</li><li id="apig-en-api-180713011__li1642421012595"><strong id="apig-en-api-180713011__b1466432614504">X-Auth-Token</strong>: specifies a user token only for token-based API authentication. The user token is a response to the API used to obtain a user token.<div class="note" id="apig-en-api-180713011__note13771123325011"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="apig-en-api-180713011__p1513412221808">In addition to supporting token-based authentication, APIs also support authentication using access key ID/secret access key (AK/SK). During AK/SK-based authentication, an SDK is used to sign the request, and the <strong id="apig-en-api-180713011__b14649044101320">Authorization</strong> (signature information) and <strong id="apig-en-api-180713011__b74561241131312">X-Sdk-Date</strong> (time when the request is sent) header fields are automatically added to the request.</p>
|
|
<p id="apig-en-api-180713011__p1577123365010">For more information, see <a href="apig-api-190529268.html#apig-api-190529268__en-us_topic_0121671869_section0390282152">AK/SK-based Authentication</a>.</p>
|
|
</div></div>
|
|
<p id="apig-en-api-180713011__p42118461957">The API used to obtain a user token does not require authentication. Therefore, only the <strong id="apig-en-api-180713011__b534017526140">Content-Type</strong> field needs to be added to requests for calling the API. An example of such requests is as follows:</p>
|
|
<pre class="screen" id="apig-en-api-180713011__screen84251747143511">POST https://{iam_endpoint}/v3/auth/tokens
|
|
Content-Type: application/json</pre>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="apig-en-api-180713011__section14612192315587"><h4 class="sectiontitle">Request Body</h4><p id="apig-en-api-180713011__p23132011213">The body of a request is often sent in a structured format as specified in the <strong id="apig-en-api-180713011__b29661657731">Content-Type</strong> header field. The request body transfers content except the request header.</p>
|
|
<p id="apig-en-api-180713011__p1847214711331">The request body varies between APIs. Some APIs do not require the request body, such as the APIs requested using the GET and DELETE methods.</p>
|
|
<p id="apig-en-api-180713011__p105261225101112">In the case of the API used to create an API group (dedicated gateways), the request parameters and parameter description can be obtained from the API request. The following provides an example request with a body included. Replace <em id="apig-en-api-180713011__i727953715615">name</em> (API group name) and <em id="apig-en-api-180713011__i17191734115611">remark</em> (API group description) with the actual values.</p>
|
|
<pre class="screen" id="apig-en-api-180713011__screen6140617194816">POST https://<em id="apig-en-api-180713011__i4324529339"><strong id="apig-en-api-180713011__b2325192915318">{apig_endpoint}</strong></em>/v2/{project_id}/v2/{project_id}/apigw/instances/{instance_id}/api-groups
|
|
Content-Type: application/json
|
|
X-Auth-Token: <strong id="apig-en-api-180713011__b198821847175120"><em id="apig-en-api-180713011__i11166134775116">xxxx</em></strong>
|
|
{
|
|
"name": "<em id="apig-en-api-180713011__i169756514111"><strong id="apig-en-api-180713011__b9704195118116">APIGroup_test</strong></em>",
|
|
"remark": "<em id="apig-en-api-180713011__i18129012171116"><strong id="apig-en-api-180713011__b133861359161113">api group remark</strong></em>"
|
|
}</pre>
|
|
<p id="apig-en-api-180713011__p1859663401915">If all data required for the API request is available, you can send the request to call the API through <a href="https://curl.haxx.se/" target="_blank" rel="noopener noreferrer">curl</a>, <a href="https://www.getpostman.com/" target="_blank" rel="noopener noreferrer">Postman</a>, or coding.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="apig-en-api-180713003.html">Calling APIs</a></div>
|
|
</div>
|
|
</div>
|
|
|