Creating a Request Using the REST API

Constructing an HTTP Request

An HTTP request consists of four parts: request method, request URL, request header, and request body.

Method

The following table describes the request methods supported by OBS.

Table 1 Request methods supported by OBS

Method

Description

GET

Requests the server to return a specific resource, for example, a bucket list or object.

PUT

Requests the server to store a specific resource, for example, a bucket or object.

POST

Requests the server to store a special resource or perform a special operation, for example, part uploading or merging.

DELETE

Requests a server to delete specified resources, for example, an object.

HEAD

Requests the server to return the digest of a specific resource, for example, object metadata.

OPTIONS

The request server checks whether the user has the operation permission for a resource. The CORS needs to be configured for the bucket.

URL

Example URL: <schema>://<bucketname>.<endpoint>/<objectname>?querystrings

  • Schema: HTTP or HTTPS
  • bucketname: name of the bucket
  • Endpoint: Domain name of the region where the bucket resides
  • objectname: name of the object
  • querystrings: query parameters

All API requests except those for the bucket list must contain the bucket name. Based on the DNS resolution performance and reliability, OBS requires that the bucket name must be placed in front of the EndPoint when a request carrying a bucket name is constructed to form a three-level domain name, also mentioned as virtual hosting access domain name.

For example, you have a bucket named test-bucket in the cn-north-4 region, and you want to access the ACL of an object named test-object in the bucket. The endpoint of the cn-north-4 region is obs.cn-north-4.myhuaweicloud.com, the correct URL is https://test-bucket.obs.cn-north-4.myhuaweicloud.com/test-object?acl.

Request Header

HTTP headers used by OBS are classified into the following types:

  • Standard HTTP header
  • OBS-defined header

The user-defined header that is always prefixed with x-obs-, such as x-obs-date and x-obs-acl.

Each REST API operation defines some optional headers and mandatory headers. Some headers need to be involved in the request signature calculation. For details about the differences API operations, see the Object Storage Service API Reference.

Request Message Body

Not all API operations need to carry the request body. Generally, only the operations defined by the PUT and POST methods need to carry the request body. The request body defined by the REST API of OBS is generally expressed in the format of XML, JSON, or binary data. For details about the differences between operations, see the Object Storage Service API Reference.

Adding a Signature to a Request

A signature can be added to a request in three forms.

Table 2 Forms of a signature in a request

Form

Description

Signature contained in the header

Usually, a signature is contained in a header. In this case, an authentication header field needs to be added to the HTTP request header in the following format:

Authorization: OBS AccessKeyID:signature

Example:

Authorization: OBS HCY8BGCN1YM5ZWYOK1MH:51KOKYY9CVvk/DtUt4W8aFHvfsc=

Signature contained in the URL

The querystring of the URL can contain a signature, which is generally used for time-limited sharing links. For example:

https://bucketname.obs.cn-north-4.myhuaweicloud.com/objectname?AccessKeyId=HCY8BGCN1YM5ZWYOK1MH&Expires=1528857302&Signature=OgynyFAkBRU6FUHkEqsMVsPolok=

Signature contained in the POST table

The POST table can contain a signature, which is generally used in browser upload scenarios. For example:

------WebKitFormBoundaryx4WluntRxFeG3GAD
Content-Disposition: form-data; name="AccessKeyId"

HCY8BGCN1YM5ZWYOK1MH
------WebKitFormBoundaryx4WluntRxFeG3GAD
Content-Disposition: form-data; name="signature"

Bpj82MEqa23d7GEot7LCqJY8Zdg=

For details about how to calculate the signature, see Signing a Request.

STS Temporary Access to OBS