How to get URL of a thing from a name/id

Does anyone have a working example or link to some running demo code that shows how to successfully use removeThing from “@inrupt/solid-client”? I have tried:

let items_dataset = await getSolidDataset(items_URL, { fetch: solid_fetch })
const thing = createThing({ name: id }) // a thing with the same name/id was previous saved to that dataset.
items_dataset = removeThing(items_dataset, thing)
saveSolidDatasetAt(items_URL, items_dataset, { fetch: solid_fetch })

But it does not seem to delete that item from the dataset. I assume I need to call removeThing with a URL but how to I convert the name/id of a thing into a URL of that thing?

(originally posted on gitter app-development)

Hey @ajp -
I believe, typically, a Thing’s URL is <SolidDatasetURL>#<name> .
So, I believe you can use

const thing = getThing(items_dataset, `${items_URL}#${id}`);
items_dataset = removeThing(items_dataset , thing);
saveSolidDatasetAt(items_URL, items_dataset, { fetch: solid_fetch })

The following docs section may (eh, may not) help : Read/Write Structured Data — Inrupt JavaScript Client Libraries

2 Likes

Thank you @kay-kim ! This works perfectly:

the Thing’s URL becomes <SolidDatasetURL>#<name>

One thing that could also be of interest is the asUrl function, which takes in a Thing and optionally a base URL (if the Thing has only been created locally), and returns this Thing's URL.

1 Like