{"library":"multiblob-http","title":"multiblob-http","description":"multiblob-http is a Node.js library designed to serve content-addressed blobs over HTTP. It provides an HTTP handler, compatible with frameworks like Express, that exposes endpoints for retrieving blobs by hash (`GET /blobs/get/{id}`) and adding new blobs (`POST /blobs/add`). The library ensures efficient content delivery by setting appropriate HTTP headers, including `ETag` (based on the blob hash) and `Expires` (a year in the future), and supports HTTP range requests (RFC 7233) crucial for streaming media and partial content retrieval. The current stable version is 1.2.1, with releases appearing to follow a maintenance cadence, focusing on stability rather than frequent new features. Its primary differentiator is its tight integration with the `multiblob` package for backend storage and its robust handling of HTTP caching mechanisms for immutable, content-addressed data.","language":"javascript","status":"maintenance","last_verified":"Wed Apr 22","install":{"commands":["npm install multiblob-http"],"cli":null},"imports":["const MultiBlobHttp = require('multiblob-http')","import MultiBlobHttp from 'multiblob-http'","http.createServer(MultiBlobHttp(blobs, '/blobs')).listen(8000)"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import MultiBlob from 'multiblob';\nimport MultiBlobHttp from 'multiblob-http';\nimport http from 'http';\nimport path from 'path';\nimport fs from 'fs';\n\n// Ensure a directory exists for blobs\nconst dir = path.join(process.cwd(), 'my-blobs');\nif (!fs.existsSync(dir)) {\n  fs.mkdirSync(dir, { recursive: true });\n}\n\nconst blobs = MultiBlob(dir);\nconst port = process.env.PORT || 8000;\n\nhttp.createServer(MultiBlobHttp(blobs, '/blobs')).listen(port, () => {\n  console.log(`multiblob-http server listening on http://localhost:${port}`);\n  console.log(`GET blobs: http://localhost:${port}/blobs/get/{hash}`);\n  console.log(`POST to add: http://localhost:${port}/blobs/add`);\n});\n\n// Example of adding a blob programmatically\nasync function addExampleBlob() {\n  const content = Buffer.from('Hello, multiblob-http!');\n  const ws = blobs.createWriteStream();\n  ws.end(content);\n  const hash = await new Promise((resolve, reject) => {\n    ws.on('error', reject);\n    ws.on('finish', () => resolve(ws.hash));\n  });\n  console.log(`Added example blob with hash: ${hash}`);\n  console.log(`Try to fetch it: curl http://localhost:${port}/blobs/get/${hash}`);\n}\n\naddExampleBlob();","lang":"typescript","description":"This quickstart sets up a basic `multiblob-http` server to serve content-addressed blobs from a local directory, demonstrating how to initialize the server and programmatically add a blob.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}