MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / get

Function get

lib/webid/lib/get.mjs:3–30  ·  view source on GitHub ↗
(webid, callback)

Source from the content-addressed store, hash-verified

1import { URL } from 'url'
2
3export default function get (webid, callback) {
4 let uri
5 try {
6 uri = new URL(webid)
7 } catch (err) {
8 return callback(new Error('Invalid WebID URI: ' + webid + ': ' + err.message))
9 }
10 const headers = {
11 Accept: 'text/turtle, application/ld+json'
12 }
13 fetch(uri.href, { method: 'GET', headers })
14 .then(async res => {
15 if (!res.ok) {
16 return callback(new Error('Failed to retrieve WebID from ' + uri.href + ': HTTP ' + res.status))
17 }
18 const contentType = res.headers.get('content-type')
19 let body
20 if (contentType && contentType.includes('json')) {
21 body = JSON.stringify(await res.json(), null, 2)
22 } else {
23 body = await res.text()
24 }
25 callback(null, body, contentType)
26 })
27 .catch(err => {
28 return callback(new Error('Failed to fetch profile from ' + uri.href + ': ' + err))
29 })
30}

Callers 1

verifyFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected