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 |
---|---|---|---|
|
| The request timeout in milliseconds. |
|
|
| 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. |
|
Returns#
Name | Type | Description |
---|---|---|
|
| The HTTP status code of the response. |
|
| The HTTP status message of the response, potentially overridden by the |
|
| This command does not return any content in the |
|
| The raw |
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.