This manual contains developer documentation for Bitcache.
To get the most of the available material, you should already be familiar with the concepts Bitcache is based upon, as well as the various frequently asked questions.
Some conventions used in this manual:
| Symbol | Description |
|---|---|
| <id> | A digital fingerprint that uniquely identifies a bitstream. |
| <str> | An arbitrary text string. |
For questions concerning the developer documentation, please write to the mailing list.
There are currently two existing open-source server implementations of the Bitcache REST API: one, bitcached, is written in Ruby and is included in the Bitcache reference implementation; the other is written in PHP and available as an add-on module for the Drupal content management framework.
Note that the question of authentication is entirely orthogonal to this API; authentication would typically be implemented using standard HTTP methods, but a cookie-based session, or indeed a publicly-available repository, is equally compatible with the REST API.
| Method | Purpose |
|---|---|
OPTIONS / |
Discover set of valid HTTP methods for the bitstream index. |
OPTIONS /<id> |
Discover set of valid HTTP methods for a bitstream resource. |
INDEX / |
Retrieve full index of available bitstreams. |
INDEX /<str> |
Retrieve partial index of bitstreams based on <str>. |
GET / |
Equivalent to INDEX /. |
GET /<id> |
Download bitstream identified by <id>. |
HEAD / |
Like GET / but omit the response body. |
HEAD /<id> |
Like GET /<id> but omit the response body. |
POST / |
Upload bitstream. |
PUT /<id> |
Upload bitstream, with <id> verification. |
DELETE /<id> |
Delete bitstream identified by <id>. |
INDEX /Retrieve full index of available bitstreams.
Not defined in RFC 2616
| Header | Value |
|---|---|
| Request | |
| Accept | MIME content type |
| Response | |
| Content-Type | ... |
INDEX /<str>Retrieve partial index of bitstreams based on <str>.
Not defined in RFC 2616
| Header | Value |
|---|---|
| Request | |
| No request headers. | |
| Response | |
| Accept | "OPTIONS, GET, HEAD, PUT, DELETE" |
| Application | Status |
|---|---|
| Drupal server | Supported. |
OPTIONS /Discover set of valid HTTP methods for the bitstream index.
Defined in RFC 2616 §9.2
| Header | Value |
|---|---|
| Request | |
| No request headers. | |
| Response | |
| Accept | "OPTIONS, GET, POST" |
OPTIONS /<id>Discover set of valid HTTP methods for a bitstream resource identified by <id>.
Defined in RFC 2616 §9.2
| Header | Value |
|---|---|
| Request | |
| No request headers. | |
| Response | |
| Accept | "OPTIONS, GET, HEAD, PUT, DELETE" |
| Application | Status |
|---|---|
| Drupal server | Supported. |
HEAD /Like INDEX /, but omit the response body.
Defined in RFC 2616 §9.4
HEAD /<id>Like GET /<id> but omit the response body.
Defined in RFC 2616 §9.4
| Header | Value |
|---|---|
| Request | |
| Response | |
| Accept-Ranges | "bytes" |
| ETag | |
| Content-SHA1 | |
| Content-Type | |
| Content-Length | |
| Application | Status |
|---|---|
| Drupal server | Supported. |
GET /Equivalent to INDEX /.
Defined in RFC 2616 §9.3
GET /<id>Download bitstream identified by <id>.
Defined in RFC 2616 §9.3
| Header | Value |
|---|---|
| Request | |
| Response | |
| Accept-Ranges | "bytes" |
| ETag | |
| Content-SHA1 | |
| Content-Type | |
| Content-Length | |
| Application | Status |
|---|---|
| Drupal server | Supported. |
POST /Upload bitstream.
Defined in RFC 2616 §9.5
| Header | Value |
|---|---|
| Request | |
| Response | |
| Application | Status |
|---|---|
| Drupal server | Supported. |
PUT /<id>Upload bitstream, with <id> verification.
Defined in RFC 2616 §9.6
| Header | Value |
|---|---|
| Request | |
| Response | |
| Application | Status |
|---|---|
| Drupal server | Supported. |
DELETE /<id>Delete bitstream identified by <id>.
Defined in RFC 2616 §9.6
| Header | Value |
|---|---|
| Request | |
| Response | |
| Application | Status |
|---|---|
| Drupal server | Supported. |
The PHP API is developed as part of the Bitcache for Drupal implementation.
PHP 5.2 with SPL is required to use this API.
Implements a Bitcache REST API-compliant HTTP server.
Note that any functions that are not documented here should be considered to be internal and subject to change without notice.
Additional developer documentation may also be available in the Drupal Handbook.
Note that any functions that are not documented here should be considered to be internal and subject to change without notice.
Additional developer documentation may also be available in the Drupal Handbook.
Returns information on the available storage adapters (repository backends).
Returns information on available cryptographic algorithms.
Returns information about modules that implement hook_bitcache().
Limits future queries and operations to a particular repository.
The Bitcache module exposes a hook_bitcache() hook that third-party extension modules can implement to provide extended functionality.
For an example of implementing this hook, see the File Framework module.
Additional developer documentation may also be available in the Drupal Handbook.
Allows modules to take action when bitstreams are created or deleted, to determine fine-grained bitstream download access rights for individual users, and to define additional HTTP headers for bitstream downloads.
This is essentially an extended analog of the hook_file_download() core hook.
/**
* Implementation of hook_bitcache().
*/
function mymodule_bitcache($op, $id, &$stream = NULL) {
switch ($op) {
case 'insert':
// A new bitstream was uploaded
break;
case 'delete':
// An existing bitstream was deleted
break;
case 'access':
// Should the current user be allowed to access the given bitstream?
return node_access('view', node_load($_GET['nid']));
case 'download':
// Determine additional HTTP headers for the bitstream download
$node = node_load($_GET['nid']);
return array(
'Content-Disposition' => 'attachment; filename='. $node->title,
'Last-Modified' => gmdate('D, d M Y H:i:s', $node->changed) .' GMT',
);
}
}