Help Center/ KooDrive/ API Reference/ Calling APIs/ Making an API Request
Updated on 2024-07-30 GMT+08:00

Making an API Request

This section describes the structure of a REST API request, and uses the KooDrive API for processing files as an example to demonstrate how to call an API.

Request URI

A request URI is in the following format:

{URI-scheme}://{Endpoint}/{resource-path}?{query-string}

Although a request URI is included in the request header, most programming languages or frameworks require the request URI to be transmitted separately.

Table 1 URI parameters

Parameter

Description

URI-scheme

Protocol used to transmit requests. All KooDrive APIs use HTTPS.

Endpoint

Domain name or IP address of the server bearing the REST service. The endpoint varies between services in different regions. Currently, KooDrive is deployed only in the AP-Singapore region, and the endpoint is intl.myhuaweicloud-koodrive.com.

resource-path

Access path of an API. Obtain the path from the URI of an API. For example, the resource-path of the API used to create a batch task is /koodrive/ose/v1/jobs.

query-string

This optional parameter is used to query the data of a parameter. Ensure that a question mark (?) is included before each query parameter that is in the format of Parameter name=Parameter value. For example, ?limit=10 indicates that a maximum of 10 data records will be displayed.

For example, to create a batch task in the AP-Singapore region, obtain the endpoint of KooDrive (intl.myhuaweicloud-koodrive.com) for this region and the resource-path (/koodrive/ose/v1/jobs) in the URI of the API used to create a batch task. Then, construct the URI as follows:

https://intl.myhuaweicloud-koodrive.com/koodrive/ose/v1/jobs

To simplify URI display, only the resource-path and request method are displayed. The URI-scheme of all APIs is HTTPS, and the endpoints of all APIs in the same region are identical.

Request Methods

The HTTP protocol defines the following request methods that can be used to send a request to the server:

Table 2 HTTP methods

Method

Description

GET

Request the server to return specified resources.

POST

Request the server to add resources or perform special operations.

DELETE

Request the server to delete specified resources, for example, an object.

PUT

Request the server to update specified resources.

For example, in the case of the API used to create a batch task, the request method is POST. The request is as follows:

POST https://intl.myhuaweicloud-koodrive.com/koodrive/ose/v1/jobs

Request Header

  • Content-Type: (optional) request body type or format. The default value is application/json. Other values of this field will be provided for specific APIs if any.
  • Authorization: authentication.

Request header example:

POST https://intl.myhuaweicloud-koodrive.com/koodrive/ose/v1/jobs
Content-Type: application/json
Authorization: xxx

Request Body

The body of a request is often sent in a structured format as specified in the Content-Type header field. The request body transfers content except the request header.

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.

For the API used to process files, an example of the request body is as follows:

{
    "taskType":1    
    "actionType":101   
    "dstContainerId": IAADfsBFCO6WtAtuA315074383680425b8aa9a130cba2d4   
    "taskInfo": {
        "srcContainerId": "IAADfsBFCO6WtAtuA315074383680425b8aa9a130cba2d4"   
        "newFilePath": "Fm9UdqBNTAQDos6l1xPlFnIqXJg2-UdqA"   
        "fileInfo": [
            {
                "fileId": "FuZmQ66CF0DdpKRG1Y29Iwajbq04Nhwu3"  
            }
       
        ]
    }
}

If all data required for the API request is available, you can send the request to call the API through curl, Postman, or coding.