Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
Commands Reference

Head


The HeadSpaceCommand allows you to perform a HEAD request against a DID Space endpoint. This is useful for checking the availability of a DID Space or retrieving its basic metadata (such as headers) without downloading the entire content. This command can help you verify the existence of a space or gather information like content type or size if applicable, efficiently.

For an overview of all DID Space commands, refer to the Commands Reference. To understand how to manage objects within DID Spaces, see the Object commands.

Usage#

To use the HeadSpaceCommand, you'll typically interact with it via the SpaceClient's space.head() method. This method sends a HEAD request to the configured DID Space endpoint.

Parameters#

Name

Type

Description

Default

timeout

number

The request timeout in milliseconds.

30000

size

number

The size of the object. This parameter is typically used for object HEAD requests and might not be directly relevant for a space HEAD request, but it is defined in the input type.

0

Returns#

Name

Type

Description

statusCode

number

The HTTP status code of the response.

statusMessage

string

The HTTP status message of the response, potentially overridden by the x-message header.

data

void

This command does not return any content in the data field.

response

Response

The raw got library response object, providing access to full headers and other response details.

Example#

import { SpaceClient } from '@did-spaces/client';
import { Wallet } from '@ocap/wallet';

async function headDidSpace() {
const wallet = Wallet.fromRandom(); // Replace with your actual DID Wallet
const client = new SpaceClient({
endpoint: 'https://your-did-space-endpoint.com/app/v1',
wallet,
});

try {
const result = await client.space.head();
console.log('HEAD Request Result:');
console.log(`Status Code: ${result.statusCode}`);
console.log(`Status Message: ${result.statusMessage}`);
console.log('Response Headers:', result.response.headers);

if (result.statusCode === 200) {
console.log('DID Space is available.');
} else {
console.log(`DID Space returned an error or is not available. Status: ${result.statusCode}`);
}
} catch (error) {
console.error('Error performing HEAD request:', error);
}
}

headDidSpace();

This example demonstrates how to instantiate a SpaceClient and use the head() method to perform a HEAD request on a DID Space. It logs the status code, status message, and response headers to indicate the space's availability and metadata.


This section covered how to use the HeadSpaceCommand to query the status and metadata of your DID Space. For more advanced operations and utilities, explore the Utilities section.