### Browser Example: Authenticated Fetch with rdflib.js Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/alternate-fetches.md Provides a complete HTML and JavaScript example for using authenticated fetches with rdflib.js in a browser. This example utilizes `@inrupt/solid-client-authn-browser` for authentication and sets `window.solidFetcher` (note: `solidFetch` is preferred in newer versions). ```html ``` -------------------------------- ### Example HTTP Headers for Update Management Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/update-manager.md This example shows typical HTTP headers returned by a Solid server that inform the client about update capabilities and permissions. Inspect these headers using `curl --head URI`. ```http HTTP/1.1 200 OK X-Powered-By: solid-server/5.7.3 Vary: Accept, Authorization, Origin Access-Control-Allow-Credentials: true Access-Control-Expose-Headers: Authorization, User, Location, Link, Last-Modified, ETag, Accept-Patch, Accept-Post, Updates-Via, Allow, WAC-Allow, Content-Length, WWW-Authenticate, MS-Author-Via, X-Powered-By Allow: OPTIONS, HEAD, GET, PATCH, POST, PUT, DELETE Link: <.acl>; rel="acl", <.meta>; rel="describedBy", ; rel="type", ; rel="type", ; rel="type" WAC-Allow: user="read",public="read" MS-Author-Via: SPARQL Updates-Via: wss://solidcommunity.net Content-Type: text/html; charset=utf-8 Content-Length: 2 ETag: W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc" Date: Wed, 19 Oct 2022 18:43:08 GMT Connection: keep-alive Keep-Alive: timeout=5 ``` -------------------------------- ### Install rdflib.js for Browser (Script Include) Source: https://github.com/linkeddata/rdflib.js/blob/main/README.md Clone the repository, install dependencies, and build the browser distribution for including rdflib.js via a script tag. ```bash git clone git@github.com:linkeddata/rdflib.js.git; cd rdflib.js; npm install; ``` -------------------------------- ### Install rdflib.js for Node.js Source: https://github.com/linkeddata/rdflib.js/blob/main/README.md Install the rdflib.js package using npm for use in Node.js environments. Ensure Node.js and npm are installed. ```bash npm install --save rdflib ``` -------------------------------- ### Install rdflib.js for Browser (Bundler) Source: https://github.com/linkeddata/rdflib.js/blob/main/README.md Install the rdflib.js package using npm for use in browser environments with a bundler like Webpack. ```bash npm install rdflib ``` -------------------------------- ### Example Commit Log Structure Source: https://github.com/linkeddata/rdflib.js/blob/main/CONTRIBUTING.md Follow this structure for writing clear and informative commit messages. The first line is a short summary, followed by a blank line, and then a more detailed explanation. ```text subsystem: explaining the commit in one line Body of commit message is a few lines of text, explaining things in more detail, possibly giving some background about the issue being fixed, etc etc. The body of the commit message can be several paragraphs, and please do proper word-wrap and keep columns shorter than about 72 characters or so. That way `git log` will show things nicely even when it is indented. ``` -------------------------------- ### JSON-LD Music Composition Example Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/rdfa/person.html Model a music composition using JSON-LD, including details like the title, composers, publisher, and lyrics. ```json { "@context": "http://schema.org", "@type": "MusicComposition", "@id": "http://musicbrainz.org/work/fd1aa4f2-ba26-3a05-b72d-4392c35a073c", "name": "A Day in the Life", "composer": [ { "@type": "Person", "name": "John Lennon", "@id": "http://musicbrainz.org/artist/4d5447d7-c61c-4120-ba1b-d7f471d385b9" }, { "@type": "Person", "name": "Paul McCartney", "@id": "http://musicbrainz.org/artist/ba550d0e-adac-4864-b88b-407cab5e76af" } ], "iswcCode": "T-010.140.236-1", "inLanguage": "EN", "publisher": { "@type": "Organization", "name": "Northern Songs, Ltd.", "@id": "http://musicbrainz.org/label/26df054d-78cf-4d83-9bb1-a41816125528" }, "datePublished": "1967", "lyrics": { "@type": "CreativeWork", "text": "I read the news today oh boy..." } } ``` -------------------------------- ### CLI Example: Authenticated Fetch with Node.js Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/alternate-fetches.md Demonstrates setting up an authenticated fetch for rdflib.js in a Node.js environment using `solid-node-client`. Ensure you have logged in to your identity provider before setting `global.solidFetch`. ```javascript async function test() { const auth = new (require("solid-node-client").SolidNodeClient)(); await auth.login( your-credentials ); global.solidFetch = auth.fetch; const $rdf = global.$rdf = require('rdflib'); const kb = $rdf.graph(); const fetcher = $rdf.fetcher(kb); await fetcher.load( some-private-url ); } ``` -------------------------------- ### RDFa Sports Team Example Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/rdfa/person.html Use RDFa to mark up a sports team and its members. This example shows how to define a team, its members, and their roles with start and end dates. ```html
San Francisco 49ers
Joe Montana
1979 1992 Quarterback
``` ```html
San Francisco 49ers
Joe Montana
1979 1992 Quarterback
``` -------------------------------- ### JSON-LD Sports Team Example Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/rdfa/person.html This JSON-LD snippet models a sports team and its members, including role-specific information like start and end dates. ```json { "@context": "http://schema.org", "@type": "SportsTeam", "name": "San Francisco 49ers", "member": { "@type": "OrganizationRole", "member": { "@type": "Person", "name": "Joe Montana" }, "startDate": "1979", "endDate": "1992", "roleName": "Quarterback" } } ``` -------------------------------- ### Initialize Store and Fetcher Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/webapp-intro.html Set up an RDF graph store and a Fetcher object to handle data transfer to and from the web. The Fetcher requires the store instance. ```javascript const store = $rdf.graph(); const me = store.sym('https://example.com/alice/card#me'); const profile = me.doc(); const VCARD = new $rdf.Namespace('http://www.w3.org/2006/vcard/ns#'); const fetcher = new $rdf.Fetcher(store); ``` -------------------------------- ### Initialize UI and Test Runner Source: https://github.com/linkeddata/rdflib.js/blob/main/test/template/offline_index.html Sets up the document ready state, initializes UI elements, and defines the test execution logic. Includes a note about test duration. ```javascript $(document).ready(function() { $("#globalresult").html("
Note: this test can take up several minutes to complete!
"); $("#viewSourceCode").click(function () { viewSource("test_rdfparser.js"); }); $('#closeSourceView').live('click', function(){ hideSource(); }); $("#reset").click(function () { location.reload(true); }); $('#goOffline').iphoneSwitch("off", function() { goOffline(); }, function() { goOnline(); }, { switch_path: '../img/iphone_switch.png', switch_on_container_path: '../img/iphone_switch_container_on.png', switch_off_container_path: '../img/iphone_switch_container_off.png' } ); $('#runTests').click(function () { tcXXXXPassed = true; $('#tocTCXXXX').html(""); $("#detailedresults").html(testTCXXXX(true)); if(tcXXXXPassed) $("#globalresult").html("
Overall result: PASSED
"); else $("#globalresult").html("
Overall result: FAILED
"); }); }); ``` -------------------------------- ### Microdata Invoice Example Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/rdfa/person.html Represents an invoice for services using Microdata with schema.org vocabulary. This example includes references to orders and products. ```html

New furnace and installation

ACME Home Heating
Jane Doe
2015-01-30
0.00 USD
0.00 USD
furnace 2014-12-01 123ABC
ACME Furnace 3000
furnace installation 2014-12-02
furnace installation
``` -------------------------------- ### Discovering an Inbox with HTTP GET Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html Use an HTTP GET request to discover the Inbox. The response is expected in JSON-LD compact form. ```http GET / HTTP/1.1 ``` -------------------------------- ### Initialize Fetcher and Navigate to Subject Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/rdfa/test2.html Sets up the cross-site proxy template and navigates to a specific subject URI when the DOM is ready. Ensure the proxy URI is correctly configured for cross-origin requests. ```javascript document.addEventListener('DOMContentLoaded', function() { var uri = window.location.href; var data_uri = window.document.title = uri.slice(0, uri.lastIndexOf('/')+1) + 'book.ttl#this'; var path = uri.indexOf('/', uri.indexOf('//') +2) + 1; var origin = uri.slice(0, path); // var proxy_uri = origin + 'xss?uri={uri}' // var proxy_uri = 'https://data.fm/proxy?uri={uri}' // Temp hack @@ var proxy_uri = 'https://databox.me/,proxy?uri={uri}' // Temp hack @@ $rdf.Fetcher.crossSiteProxyTemplate = proxy_uri; data_uri = 'http://melvincarvalho.com/'; var subject = $rdf.sym(data_uri); tabulator.outline.GotoSubject(subject, true, undefined, true, undefined); }); ``` -------------------------------- ### Retrieving a Specific Notification with HTTP GET Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html A consumer retrieves an individual notification from the Inbox by making an HTTP GET request to its specific URL. ```http GET /inbox/14a792f0 HTTP/1.1 ``` -------------------------------- ### Initialize and Run Offline Indexing Tests Source: https://github.com/linkeddata/rdflib.js/blob/main/test/tc0005/offline_index.html Sets up the test environment, handles UI interactions for switching online/offline modes, and runs the offline indexing tests. Includes a note about test duration. ```javascript $(document).ready(function() { $("#globalresult").html("
Note: this test can take up several minutes to complete!
"); $("#viewSourceCode").click(function () { viewSource("test_rdfparser.js"); }); $('#closeSourceView').live('click', function(){ hideSource(); }); $("#reset").click(function () { location.reload(true); }); $('#goOffline').iphoneSwitch("off", function() { goOffline(); }, function() { goOnline(); }, { switch_path: '../img/iphone_switch.png', switch_on_container_path: '../img/iphone_switch_container_on.png', switch_off_container_path: '../img/iphone_switch_container_off.png' }); $('#runTests').click(function () { tcXXXXPassed = true; $('#tocTCXXXX').html(""); $("#detailedresults").html(testTCXXXX(true)); if(tcXXXXPassed) $("#globalresult").html("
Overall result: PASSED
"); else $("#globalresult").html("
Overall result: FAILED
"); }); }); ``` -------------------------------- ### Requesting Inbox Listing with HTTP GET Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html A consumer requests the Inbox using an HTTP GET request. The receiver responds with a listing of notifications. ```http GET /inbox/ HTTP/1.1 ``` -------------------------------- ### Initialize Test Harness and UI Elements Source: https://github.com/linkeddata/rdflib.js/blob/main/test/tc0004/index.html Sets up the test harness on document ready, initializes UI elements like the results display, source code viewer, reset button, and an offline switch. It also attaches event listeners for running tests and managing offline mode. ```javascript $(document).ready(function() { $("#globalresult").html("
Note: this test can take up to several minutes to complete. Consider using OFF-LINE mode (left upper corner).
"); $("#viewSourceCode").click(function () { viewSource("test_rdfparser.js", true); }); $('#closeSourceView').live('click', function(){ hideSource(); }); $("#reset").click(function () { location.reload(true); }); $('#goOffline').iphoneSwitch("off", function() { goOffline(); }, function() { goOnline(); }, { switch_path: '../img/iphone_switch.png', switch_on_container_path: '../img/iphone_switch_container_on.png', switch_off_container_path: '../img/iphone_switch_container_off.png' } ); $('#runTests').click(function () { tc0004Passed = true; $('#tocTC0004').html(""); $("#detailedresults").html(testTC0004(true)); if(tc0004Passed) $("#globalresult").html("
Overall result: PASSED
"); else $("#globalresult").html("
Overall result: FAILED
"); }); }); ``` -------------------------------- ### Initialize Test Harness and Event Listeners Source: https://github.com/linkeddata/rdflib.js/blob/main/test/tc0007/index.html Sets up the document ready event to initialize the test harness. It attaches click handlers for viewing source code and closing the source view, then executes the TC0007 test and displays the overall result. ```javascript $(document).ready(function() { $("#viewSourceCode").click(function () { viewSource("test_UUU.js"); }); $('#closeSourceView').live('click', function(){ hideSource(); }); $("#detailedresults").html(testTC0007(true, newResults)); if(tc0007Passed) $("#globalresult").append("
Overall result: PASSED
"); else $("#globalresult").html("
Overall result: FAILED
"); }); ``` -------------------------------- ### Create a new rdflib.js store (graph shortcut) Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/webapp-intro.html Initialize a new rdflib.js data store using the graph() shortcut. This is a convenient way to create a new store. ```javascript const store = $rdf.graph(); ``` -------------------------------- ### GET Receiver reports Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html Responds to GET requests with JSON-LD or RDF. Lists notification URIs with ldp:contains. Notifications are available as JSON-LD or RDF. The inbox has type ldp:Container and may advertise constraints with ldp:constrainedBy. ```APIDOC ## GET /inbox ### Description Retrieves notifications from the inbox. The response format can be JSON-LD or RDF, depending on the `Accept` header. ### Method GET ### Endpoint /inbox ### Parameters #### Header Parameters - **Accept** (string) - Optional - Specifies the desired response format (e.g., `application/ld+json`, `application/rdf+xml`, `*/*`). Defaults to RDF if not specified or `*/*`. ### Response #### Success Response (200 OK) - **Content** (JSON-LD or RDF) - The list of notification URIs, potentially including `ldp:contains`. - **ldp:constrainedBy** (string) - Optional - Header - URI advertising constraints. #### Notes - The inbox is of type `ldp:Container`. - The list of notification URIs may be restricted based on access control. ``` -------------------------------- ### Response to Sending a Notification Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html An example HTTP response indicating successful creation of a notification after a POST request. ```http HTTP/1.1 201 Created ``` -------------------------------- ### Initialize RDFLib.js Store, Fetcher, and UpdateManager Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/webapp-intro.html Sets up the necessary RDFLib.js objects for interacting with the web, including a graph store, a fetcher for loading resources, and an UpdateManager for sending changes. ```javascript const store = $rdf.graph() const fetcher = new $rdf.Fetcher(store) const updater = new $rdf.UpdateManager(store) ``` -------------------------------- ### Run Tests Source: https://github.com/linkeddata/rdflib.js/blob/main/CONTRIBUTING.md Execute the project's test suite using npm. Ensure all tests pass before submitting changes. ```sh $ npm test ``` -------------------------------- ### Agent Delegation with WebID Source: https://github.com/linkeddata/rdflib.js/blob/main/tests/serialize/csarven-ori.html Example of an agent delegating another agent to act on its behalf, using WebID. ```turtle auth:delegatesTo . ``` -------------------------------- ### Using Hub for Forking and PRs Source: https://github.com/linkeddata/rdflib.js/blob/main/CONTRIBUTING.md Utilize the 'hub' command-line tool to fork the repository, create branches, push changes, and initiate pull requests. ```bash $ git clone https://github.com/linkeddata/rdflib.js $ cd rdflib.js # to fork the repository $ hub fork # to fork the repository $ git checkout -b feature-branch # after committing your changes, push to your repo $ git push your_username feature-branch # start a PR $ hub pull-request ``` -------------------------------- ### Local Identifiers with Default Prefix in Turtle Source: https://github.com/linkeddata/rdflib.js/blob/main/Documentation/turtle-intro.html Example using local identifiers with the default ':' prefix, which is assumed by rdflib.js. ```turtle :this a :Example; :age 123. ```