Example about supplying fetch with solid-client-authn-node library

Hello all,

I am working on building a simple web server app with Node and Solid. However, I am having trouble understanding how to use session.fetch() with the solid client methods. I can use it as canonical fetch to perform requests, however I want to use it in methods like saveSolidDatasetAt etc etc and I am not sure how to supply it as an option correctly. Could anyone point me to some example code or something small they wrote themselves?

Thanks in advance

I haven’t worked with node, but I guess this should work:

  const myDataset = await getSolidDataset(
    "https://example.org/", 
    { fetch: session.fetch.bind(session) }
  );

And here I’ve found this test file, which uses it multiple times: solid-client-js/wac.test.ts at main · inrupt/solid-client-js · GitHub

1 Like

Thanks for the help! I forgot to pass it as a function reference and was instead passing it as a function call.

Just to clarify, you just need to do:

const myDataset = await getSolidDataset(
    "https://example.org/", 
    { fetch: session.fetch }
  );

The .bind(session) isn’t really needed, as we’ve specifically coded the method to not be bothered by it’s this object (it’s already bound to the session class instance)

2 Likes