{"id":47373,"library":"dat-fetch","title":"dat-fetch","description":"Implementation of the Fetch API that uses the Dat SDK for loading peer-to-peer content from hyper:// and dat:// URLs. Version 5.1.1 provides a browser-compatible fetch interface for reading and writing data in Dat archives. Release cadence is sporadic. It automatically resolves domain names via dat-dns, handles directory listings, and supports common HTTP methods. Requires the dat-sdk peer dependency. Suitable for building decentralized web applications.","status":"active","version":"5.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/RangerMauve/dat-fetch","tags":["javascript","dat","fetch"],"install":[{"cmd":"npm install dat-fetch","lang":"bash","label":"npm"},{"cmd":"yarn add dat-fetch","lang":"bash","label":"yarn"},{"cmd":"pnpm add dat-fetch","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; provides the underlying Dat protocol implementation for reading/writing archives","package":"dat-sdk","optional":false}],"imports":[{"note":"The module exports a factory function that must be called to create a fetch instance. In CJS, require('dat-fetch')() is correct but ESM import is preferred.","wrong":"const fetch = require('dat-fetch')()","symbol":"default export","correct":"import makeFetch from 'dat-fetch'"},{"note":"makeFetch is the default export, not a named export. Use default import or require and call it.","wrong":"const { makeFetch } = require('dat-fetch')","symbol":"makeFetch","correct":"import makeFetch from 'dat-fetch'"},{"note":"The module does not export a fetch function directly; it exports a factory. You must call makeFetch() to get a fetch function.","wrong":"const fetch = require('dat-fetch')","symbol":"fetch","correct":"const fetch = makeFetch(); const response = await fetch('hyper://...')"}],"quickstart":{"code":"import makeFetch from 'dat-fetch';\n\nconst fetch = makeFetch({\n  // Optional: pass Dat SDK options or Hyperdrive/resolveName\n});\n\nconst url = 'hyper://blog.mauve.moe/index.json';\ntry {\n  const response = await fetch(url);\n  if (!response.ok) {\n    console.error('Fetch failed:', response.statusText);\n    process.exit(1);\n  }\n  const data = await response.json();\n  console.log(data);\n} catch (err) {\n  console.error('Error:', err.message);\n} finally {\n  await fetch.close();\n}","lang":"typescript","description":"Shows how to import the factory, create a fetch instance, perform a GET request to a hyper:// URL, parse JSON response, and clean up."},"warnings":[{"fix":"Use hyper:// instead of dat://. If you must support dat://, pass a custom resolveName function that converts dat:// to hyper://.","message":"In version 5.0.0, the package switched from dat:// to hyper:// URLs. Previously supported dat:// URLs will no longer resolve unless you configure a resolver.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use default import: import makeFetch from 'dat-fetch'; const fetch = makeFetch();","message":"The module exports a factory function, not a fetch function. Calling require('dat-fetch')() is correct in CJS, but in ESM you must use import makeFetch from 'dat-fetch' and then call makeFetch().","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Run npm install dat-sdk alongside dat-fetch.","message":"The 'dat-sdk' peer dependency must be installed separately. Missing it will cause runtime errors when trying to resolve names or access archives.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Use Node.js 14 or higher.","message":"The package does not support Node.js 12 and below. Engine requirements are not specified, but dependencies may fail on older Node versions.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Always call fetch.close() to be safe, but understand it may be a no-op in advanced usage.","message":"The close() method on the fetch instance only releases SDK resources if the SDK was auto-created (i.e., you didn't pass Hyperdrive and resolveName). If you supplied those, close() does nothing.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'5.1.1':25 'api':8 'applic':74 'archiv':40 'automat':46 'browser':29 'browser-compat':28 'build':71 'cadenc':42 'common':59 'compat':30 'content':20 'dat':2,12,39,52,65,76 'dat-dn':51 'dat-fetch':1 'dat-sdk':64 'data':37 'decentr':72 'depend':68 'directori':55 'dns':53 'domain':48 'fetch':3,7,31,77 'handl':54 'http':60 'implement':4 'interfac':32 'javascript':75 'list':56 'load':15 'method':61 'name':49 'peer':17,19,67 'peer-to-p':16 'provid':26 'read':34 'releas':41 'requir':62 'resolv':47 'sdk':13,66 'sporad':44 'suitabl':69 'support':58 'url':23 'use':10 'version':24 'via':50 'web':73 'write':36","created_at":"2026-06-07T16:51:12.011883+00:00","updated_at":"2026-06-07T16:51:12.011883+00:00","problems":[{"fix":"Run 'npm install dat-sdk' in your project.","cause":"The peer dependency 'dat-sdk' is not installed.","error":"Error: Cannot find module 'dat-sdk'"},{"fix":"Use 'const fetch = require('dat-fetch')()' (CJS) or 'import makeFetch from 'dat-fetch'; const fetch = makeFetch();' (ESM).","cause":"The module was imported incorrectly; it exports a factory, not the fetch function.","error":"TypeError: fetch is not a function"},{"fix":"Check response.ok and response.headers.get('content-type') before calling .json().","cause":"The response may not be a valid JSON response (e.g., content-type is not application/json, or network error).","error":"TypeError: fetch(...).json is not a function"},{"fix":"Ensure the URL starts with 'hyper://' or 'dat://'. For other protocols, use a different library.","cause":"URL scheme is not supported. Only hyper:// and dat:// are allowed.","error":"Error: Invalid scheme. Expected hyper:// or dat://"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/RangerMauve/dat-fetch#readme","github":"https://github.com/RangerMauve/dat-fetch","docs":null,"changelog":null,"pypi":null,"npm":"dat-fetch","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}