• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. GET Bucket website

GET Bucket website

API Description

You can use this API to obtain the website hosting settings of a bucket.

Method Definition

ObsClient.getBucketWebsiteConfiguration(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

RedirectAllRequestsTo

Object

Redirection rule of all requests

  

HostName

String

Host name used for redirection

Protocol

String

Host name used for redirection

ErrorDocument

Object

Error page settings

  

Key

String

Page to return to when a 4XX error occurs

IndexDocument

Object

Default page settings

  

Suffix

String

Suffix that is appended to a request initiated for a directory on the website endpoint. For example, if the suffix is index.html and you request for samplebucket/images/, the data that is returned will be the object with the key name images/index.html in the samplebucket bucket. This field cannot be left blank or contain a slash (/).

RoutingRules

Object

Redirection rule information

  

RoutingRule

Array

Redirection rule list

  

Condition

Object

Matching conditions of a redirection rule

  

HttpErrorCodeReturnedEquals

String

HTTP error code to be matched when a redirection rule takes effect

KeyPrefixEquals

String

Object name prefix to be matched when a redirection rule takes effect

Redirect

Object

Details about a redirection request

  

Protocol

String

Protocol used for redirection

HostName

String

Host name used for redirection

ReplaceKeyPrefixWith

String

Object name prefix used in the redirection request

ReplaceKeyWith

String

Object name used in the redirection request. This parameter cannot be used together with ReplaceKeyPrefixWith.

HttpRedirectCode

String

HTTP status code in the response to the redirection request

Sample Code

obsClient.getBucketWebsiteConfiguration({
       Bucket : 'bucketname'
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('RedirectAllRequestsTo:');
                     console.log('HostName-->' + result.InterfaceResult.RedirectAllRequestsTo['HostName']);
                     console.log('Protocol-->' + result.InterfaceResult.RedirectAllRequestsTo['Protocol']);
                     console.log('IndexDocument[Suffix]-->' + result.InterfaceResult.IndexDocument['Suffix']);
                     console.log('ErrorDocument[Key]-->' + result.InterfaceResult.ErrorDocument['Key']);
                     console.log('RoutingRules:');
                     for(let i=0;i<result.InterfaceResult.RoutingRules.RoutingRule.length;i++){
                           console.log('RoutingRule[' + i + ']:');
                           let RoutingRule = result.InterfaceResult.RoutingRules.RoutingRule[i];
                           console.log('Condition[HttpErrorCodeReturnedEquals]-->' + RoutingRule['Condition']['HttpErrorCodeReturnedEquals']);
                           console.log('Condition[KeyPrefixEquals]-->' + RoutingRule['Condition']['KeyPrefixEquals']);
                           console.log('Redirect[HostName]-->' + RoutingRule['Redirect']['HostName']);
                           console.log('Redirect[HttpRedirectCode]-->' + RoutingRule['Redirect']['HttpRedirectCode']);
                           console.log('Redirect[Protocol]-->' + RoutingRule['Redirect']['Protocol']);
                           console.log('Redirect[ReplaceKeyPrefixWith]-->' + RoutingRule['Redirect']['ReplaceKeyPrefixWith']);
                           console.log('Redirect[ReplaceKeyWith]-->' + RoutingRule['Redirect']['ReplaceKeyWith']);
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});