Repository navigation
Expand file tree
/
Copy pathusage-examples.html
More file actions
163 lines (148 loc) · 7.24 KB
/
Copy pathusage-examples.html
File metadata and controls
163 lines (148 loc) · 7.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.11.1 from src/site/apt/usage-examples.apt.vm at 2023-08-30
| Rendered using Apache Maven Fluido Skin 1.11.1
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 1.11.1" />
<title>Inrupt Java Client Libraries – </title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.11.1.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script src="./js/apache-maven-fluido-1.11.1.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<header>
<div id="banner">
<div class="pull-left"><div id="bannerLeft"><h1>Inrupt Java Client Libraries</h1>
</div>
</div>
<div class="pull-right"><a href="index.html" id="bannerRight"><img src="images/inrupt_logo-2020.svg" alt="Inrupt" style="" /></a></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2023-08-30<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 1.0.1</li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Inrupt Client</li>
<li><a href="index.html" title="Home"><span class="none"></span>Home</a></li>
<li><a href="getting-started.html" title="Getting Started"><span class="none"></span>Getting Started</a></li>
<li class="active"><a><span class="none"></span>Usage Examples</a></li>
<li><a href="client-options.html" title="Client Options"><span class="none"></span>Client Options</a></li>
<li><a href="session-management.html" title="Session Management"><span class="icon-chevron-right"></span>Session Management</a></li>
<li><a href="data-modeling.html" title="Data Modeling"><span class="icon-chevron-right"></span>Data Modeling</a></li>
<li><a href="apidocs/" title="Documentation"><span class="none"></span>Documentation</a></li>
<li><a href="licenses.html" title="License"><span class="none"></span>License</a></li>
<li><a href="modules.html" title="Modules"><span class="none"></span>Modules</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10" >
<section>
<h2><a name="Usage_Examples"></a>Usage Examples</h2>
<p>The Inrupt Java Client Libraries come with abstractions such as <code>SolidRDFSource</code> that make it very easy to interact with data stored in a <a class="externalLink" href="https://solidproject.org/about">Solid Pod</a>. </p><section>
<h3><a name="What_you_will_need"></a>What you will need</h3>
<ul>
<li><a class="externalLink" href="https://start.inrupt.com/profile">A Solid Pod</a></li>
<li>About 15 minutes</li>
<li>Your favorite text editor or IDE</li>
<li>Java 11 or later</li>
<li>Maven 3.5 or later</li></ul></section><section>
<h3><a name="How_to_complete"></a>How to complete</h3>
<p>Take a look at the next simple examples and try them out.</p>
<p>Next you will have to decide on a <a href="./client-options.html">client option</a> based on your application needs.</p></section><section>
<h3><a name="Working_with_resources"></a>Working with resources</h3>
<p>In the next examples the <code>podStorage</code> is what you get when you <a class="externalLink" href="https://start.inrupt.com/profile">register for a Pod</a>. And it looks something like <code>https://storage.inrupt.com/d2a8b8b3-1a0f-41cb-a8d1-bc93842fa00d/</code>.</p></section><section>
<h3><a name="Create_a_resource"></a>Create a resource</h3>
<div class="source"><pre class="prettyprint">import java.net.URI;
import com.inrupt.client.util.URIBuilder;
import com.inrupt.client.solid.SolidSyncClient;
public void createEmptyResource() {
SolidSyncClient client = SolidSyncClient.getClient();
URI newResourceURI = URIBuilder.newBuilder(podStorage).path("newResource").build();
try (SolidRDFSource newResource = new SolidRDFSource(newResourceURI, null, null)) {
client.create(newResource);
}
}
</pre></div></section><section>
<h3><a name="Read_a_resource"></a>Read a resource</h3>
<div class="source"><pre class="prettyprint">import java.net.URI;
import com.inrupt.client.util.URIBuilder;
import com.inrupt.client.solid.SolidSyncClient;
public void readResource() {
SolidSyncClient client = SolidSyncClient.getClient();
URI newResourceURI = URIBuilder.newBuilder(podStorage).path("newResource").build();
SolidRDFSource resource = client.read(newResourceURI, SolidRDFSource.class);
}
</pre></div></section><section>
<h3><a name="Update_a_resource"></a>Update a resource</h3>
<p>We have created and read a resource which we named <code>newResource</code>. However, the resource is empty, it has no content. Let's add a triple inside.</p>
<div class="source"><pre class="prettyprint">import java.net.URI;
import com.inrupt.client.util.URIBuilder;
import com.inrupt.client.solid.SolidSyncClient;
import com.inrupt.client.spi.RDFFactory;
import org.apache.commons.rdf.api.Dataset;
import org.apache.commons.rdf.api.RDF;
public void updateResource() {
SolidSyncClient client = SolidSyncClient.getClient();
URI newResourceURI = URIBuilder.newBuilder(podStorage).path("newResource").build();
RDF rdf = RDFFactory.getInstance();
Dataset newDataset = rdf.createDataset();
newDataset.add(null,
rdf.createIRI("https://resource.test/subject"),
rdf.createIRI("https://resource.test/predicate"),
rdf.createLiteral("TestObject"));
try (SolidRDFSource updatedResource = new SolidRDFSource(newResourceURI, newDataset, null)) {
client.update(updatedResource);
}
}
</pre></div></section><section>
<h3><a name="Delete_a_resource"></a>Delete a resource</h3>
<div class="source"><pre class="prettyprint">import com.inrupt.client.solid.SolidSyncClient;
public void deleteResource(SolidResource resource) {
SolidSyncClient client = SolidSyncClient.getClient();
client.delete(resource);
}
</pre></div></section><section>
<h3><a name="Next_Steps"></a>Next Steps</h3>
<p>Now that you have tried some basic examples, the next step is to consider which <a href="./client-options.html">type of client</a> you want to make use of.</p></section></section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>© 2023
<a href="https://inrupt.com">Inrupt, Inc</a>
</p>
</div>
</div>
</footer>
<script>
if(anchors) {
anchors.add();
}
</script>
</body>
</html>