-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAPI.html
More file actions
1516 lines (1357 loc) · 79.3 KB
/
API.html
File metadata and controls
1516 lines (1357 loc) · 79.3 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>API (1.0.0) | rerum_server</title>
<meta property="og:title" content="API (1.0.0)" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="A NodeJS web service for interaction with the RERUM digital object repository." />
<meta property="og:description" content="A NodeJS web service for interaction with the RERUM digital object repository." />
<link rel="canonical" href="https://store.rerum.io/API.html" />
<meta property="og:url" content="https://store.rerum.io/API.html" />
<meta property="og:site_name" content="rerum_server" />
<script type="application/ld+json">
{"description":"A NodeJS web service for interaction with the RERUM digital object repository.","url":"https://store.rerum.io/API.html","@type":"WebPage","headline":"API (1.0.0)","@context":"https://schema.org"}
</script>
<link rel="stylesheet" href="stylesheets/api.css">
</head>
<body class="container">
<div class="container-lg px-3 my-5 markdown-body">
<h1><a target="_blank" href="https://store.rerum.io/"><img src="https://rerum.io/logo.png" alt="logo"/></a>RERUM API v1</h1>
<h3>
TLDR: I Just Want to Use It
</h3>
<p>
If you would like to see an example of a web application leveraging the RERUM API visit the official RERUM Sandbox and public sandbox API <a target="_blank" href="https://tinydev.rerum.io">https://tinydev.rerum.io</a>. You can use the following RERUM Sandbox API links to give your application simple CRUD and query abilities.
</p>
<ul id="tt_example">
<li>https://tinydev.rerum.io/app/create Uses the rules established by RERUM <a href="#create">create</a></li>
<li>https://tinydev.rerum.io/app/update Uses the rules established by RERUM PUT <a href="#update">update</a>
</li>
<li>https://tinydev.rerum.io/app/delete Uses the rules established by RERUM <a href="#delete">delete</a></li>
<li>https://tinydev.rerum.io/app/query Uses the rules established by RERUM <a href="#custom-query">custom query</a></li>
</ul>
<p class="warning">
Your data will be public and could be removed at any time. The sandbox functions as a public testbed and uses the development API; it is <u>not</u> meant for production applications.
</p>
<!-- TOC -->
<h1 id="api-100">API (1.0.0)</h1>
<ul>
<li><a href="#api-10">API (1.0.0)</a>
<ul>
<li><a href="#registration"><b>Registration Prerequisite</b></a></li>
<li><a href="#authorization"><b>Access Token Requirement</b></a></li>
<li><a href="#get">GET</a>
<ul>
<li><a href="#single-record-by-id">Single record by id</a></li>
<li><a href="#history-tree-before-this-version">History tree before this version</a></li>
<li><a href="#history-tree-since-this-version">History tree since this version</a></li>
</ul>
</li>
<li><a href="#post">POST</a>
<ul>
<li><a href="#access-token-proxy">Access Token Proxy</a></li>
<li><a href="#refresh-token-proxy">Refresh Token Proxy</a></li>
<li><a href="#create">Create</a></li>
<li><a href="#bulk-create">Bulk Create</a></li>
<li><a href="#custom-query">Custom Query</a></li>
<li><a href="#http-post-method-override">HTTP POST Method Override</a></li>
</ul>
</li>
<li><a href="#put">PUT</a>
<ul>
<li><a href="#update">Update</a></li>
<li><a href="#overwrite">Overwrite</a></li>
<li><a href="#bulk-update">Bulk Update</a></li>
</ul>
</li>
<li><a href="#patch">PATCH</a>
<ul>
<li><a href="#patch-update">Patch Update</a></li>
<li><a href="#add-properties">Add Properties</a></li>
<li><a href="#remove-properties">Remove Properties</a></li>
<li><a href="#rerum-released">RERUM released</a></li>
</ul>
</li>
<li><a href="#delete">DELETE</a></li>
<li><a href="#__rerum">__rerum</a>
<ul>
<li><a href="#history">History</a></li>
<li><a href="#generator-attribution">Attribution</a></li>
</ul>
</li>
<li><a href="#authentication">Authentication</a></li>
<li><a href="#context">@context</a></li>
<li><a href="#iiif">IIIF</a></li>
<li><a href="#web-annotation">Web Annotation</a></li>
<li><a href="#rerum-responses">RERUM Responses</a></li>
</ul>
</li>
</ul>
<!-- /TOC -->
<h2 id="registration">Registration Prerequisite</h2>
<p>
<u>Access Tokens are required in order to communicate with the RERUM API</u>. These Access Tokens are for the <i>application</i> so that RERUM can verify which application is making an API request and attribute data properly. To register, one must visit the registration page at <a target="_blank" href="https://devstore.rerum.io">https://devstore.rerum.io/v1/</a>. Registration requires an E-mail address and a name, which is typically a webmaster or principal investigator in charge of the application's wellbeing. The result of registration is a Refresh Token and an Access Token. <b>Do not lose the Refresh Token</b> as it is used by the application to get new valid Access Token throughout the application lifespan. To see how this process works, see the TinyThings application which has a <a target="_blank" href="https://github.com/CenterForDigitalHumanities/TinyNode/blob/main/tokens.js">token module that implements token refreshes</a>. Registrants can get new Refresh Tokens from the RERUM registration page by logging in again. When a new token is provided old tokens are expired.
<p class="alert">
Note that the same Refresh Token and Access Token can be used for multiple applications. However, the data from each of those applications will share the same application <code>generator</code> attribution and will not be considered separate applications.
</p>
</p>
<h2 id="authorization">Authorization Header Bearer Tokens</h2>
<p>
Create, Update, and Delete requests require valid Access Tokens or else the API will return Unauthorized errors. To provide an Access Token, application HTTP requests use the <a target="_blank" href=""><code>Authorization</code></a> header to provide a 'Bearer Token'. It has the format 'Beaer: Access Token' as seen below.
<div class="exHeading">Authorization Header Example</div>
<pre><code class="jsExample">
"Authorization": "Bearer eyJz93a...k4laUWw"
</code></pre>
You will see many examples in this document that use this HTTP header.
</p>
<h2 id="welcome">Welcome!</h2>
<p>
<b>For those who Copy and Paste</b> please note that all examples are using the <i>development</i> (devstore.rerum.io) version of the RERUM API, not the production version (store.rerum.io). Only use production once you have become confident with the API and have confirmed your application is generating data as expected.
</p>
<h2 id="get">GET</h2>
<h3 id="single-record-by-id">Single record by id</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/id/_id</code></td>
<td><code class="language-plaintext highlighter-rouge">empty</code></td>
<td>200 <code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">_id</code></strong>—the id of the record in
RERUM.</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The record
with identifier <code class="language-plaintext highlighter-rouge">_id</code></li>
</ul>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
const entity = await fetch("https://devstore.rerum.io/v1/id/11111").then(resp => resp.json()).catch(err => {throw err})
</code></pre>
</p>
<p>
This can be used directly in the browser. Try it to see what the response <code>resp</code> looks like.</span>
<a target="_blank" href="https://devstore.rerum.io/v1/id/11111">https://devstore.rerum.io/v1/id/11111</a>
</p>
<h3 id="history-tree-before-this-version">History tree before this version</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/history/_id</code></td>
<td><code class="language-plaintext highlighter-rouge">empty</code></td>
<td>200 <code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">_id</code></strong>—the id of the record in
RERUM.</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array
of the resolved records of all parent history records</li>
</ul>
<p>
As records in RERUM are altered, the previous state is retained in
a history tree. Requests return ancestors of this record on its
branch. The records in the array are listed in inorder traversal but
ignoring other branches.
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
const history_array = await fetch("https://devstore.rerum.io/v1/history/11111").then(resp => resp.json()).catch(err => {throw err})
</code></pre>
</p>
<p>
This can be used directly in the browser. Try it to see what the response <code>resp</code> looks like.</span>
<a target="_blank" href="https://devstore.rerum.io/v1/history/11111">https://devstore.rerum.io/v1/history/11111</a>
</p>
<h3 id="history-tree-since-this-version">History tree since this version</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/since/_id</code></td>
<td><code class="language-plaintext highlighter-rouge">empty</code></td>
<td>200 <code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">_id</code></strong>—the id of the record in
RERUM.</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array
of the resolved records of all child history records</li>
</ul>
<p>
As records in RERUM are altered, the next state is retained in
a history tree. Requests return all descendants of this record from all branches.<br />
The records in the array are listed in preorder traversal.
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
const since_array = await fetch("https://devstore.rerum.io/v1/since/11111").then(resp => resp.json()).catch(err => {throw err})
</code></pre>
</p>
<p>
This can be used directly in the browser. Try it to see what the response <code>resp</code> looks like.
<a target="_blank" href="https://devstore.rerum.io/v1/since/11111">https://devstore.rerum.io/v1/since/11111</a>
</p>
<h2 id="post">POST</h2>
<h3 id="access-token-proxy">Access Token Proxy</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/client/request-new-access-token</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>— Auth0 requirements <a
target="_blank" href="https://auth0.com/docs/tokens/refresh-token/current#use-a-refresh-token">here</a></li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">{JSON}</code></strong>— Containing
the Auth0 /oauth/token <code class="language-plaintext highlighter-rouge">JSON</code> response</li>
</ul>
<p>RERUM works as a proxy with Auth0 to help manage tokens from registered applications.</p>
<p>
<div class="exHeading">Example for Getting an Application Access Token</div>
<pre><code class="jsExample">
<span>const access_token = await fetch("https://devstore.rerum.io/client/request-new-access-token", {</span>
<span class="ind1">method: "POST",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify({</span>
<span class="ind2">"refresh_token": "faJw88b...l4leYIw"</span>
<span class="ind1">})</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.then(info => info.access_token)</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like</div>
<pre><code class="respExample">
<span>{</span>
<span class="ind1">"access_token": "eyJz93a...k4laUWw",</span>
<span class="ind1">"refresh_token": "GEbRxBN...edjnXbL",</span>
<span class="ind1">"id_token": "eyJ0XAi...4faeEoQ",</span>
<span class="ind1">"token_type": "Bearer",</span>
<span class="ind1">"expires_in": 86400</span>
<span>}</span>
</code></pre>
</p>
<h3 id="refresh-token-proxy">Refresh Tokens</h3>
<p>
Application managers must use the <a target="_blank" href="https://devstore.rerum.io">RERUM Registration Page</a> to get new Refresh Tokens. Applications are not able to ask for new Refresh Tokens like they can ask for new Access Tokens.
</p>
<h3 id="create">Create</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/create</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>201 <code
class="language-plaintext highlighter-rouge">Location: https://devstore.rerum.io/v1/id/abcdef1234567890</code>
<code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The object to create
</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—Containing
various bits of information about the create.</li>
</ul>
<p>
Add a completely new object to RERUM and receive the <code class="language-plaintext highlighter-rouge">Location</code> URI
as a response header and the complete RERUM record as the response body. Accepts only single JSON objects in the request body.
<p class="alert">
The <code class="language-plaintext highlighter-rouge">__rerum</code>, <code
class="language-plaintext highlighter-rouge">@id</code> and <code
class="language-plaintext highlighter-rouge">_id</code> properties are ignored.</p>
</p>
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const saved_obj = await fetch("https://devstore.rerum.io/v1/api/create", {</span>
<span class="ind1">method: "POST",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw" </span>
<span class="ind2"> "Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify({</span>
<span class="ind2">"hello": "world"</span>
<span class="ind1">})</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>{</span>
<span class="ind1">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind1">"hello": "world",</span>
<span class="ind1">"__rerum":{...}</span>
<span>}</span>
</code></pre>
<p class="alert"> Note that resp.headers.get("location") will return "https://devstore.rerum.io/v1/id/abcdef1234567890" </p>
</p>
<h3 id="bulk-create">Bulk Create</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/bulkCreate</code></td>
<td><code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
<td>201 <code>
<code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array of objects
to create in RERUM</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array
of the resolved records from the creation process</li>
</ul>
<p>
Add multiple completely new objects to RERUM and receive an array of the complete records as the response body.
Accepts only a single array of JSON objects in the request body. The '@id' property must not be present on the objects.
In cases where the Linked Data @context property maps '@id' to 'id', the 'id' property also must not be present.
The array of JSON objects passed may not be created in the order submitted. The response will have the URI
of the new resource or an error message as an array in the order the order the objects were processed.
When errors are encountered, the batch process will attempt to continue for all submitted items.
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const saved_objs = await fetch("https://devstore.rerum.io/v1/api/bulkCreate", {</span>
<span class="ind1">method: "POST",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw" </span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify([
<span class="ind2">{"hello": "sun"},</span>
<span class="ind2">{"goodbye": "moon"} </span>
<span class="ind1">])</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>[</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind2">"hello": "sun",</span>
<span class="ind2">"__rerum":{...}</span>
<span class="ind1">},</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/1234567890abcdef",</span>
<span class="ind2">"goodbye": "moon",</span>
<span class="ind2"> "__rerum":{...}</span>
<span class="ind1">}</span>
<span>]</span>
</code></pre>
</p>
<h3 id="custom-query">Custom Query</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/query?limit=10&skip=0</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—the properties in JSON
format for the query</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array
of the resolved records that match the query</li>
</ul>
<p>
This simple format will be made more complex in the future, but should serve the basic needs as it is.
RERUM will test for property matches. By default, this is limited to 10 records in the response to guard against unreasonable queries. To allow for more records in the response one can add the URL parameter <code>limit</code> to the query requests. If you expect the query request will have a very large response with many objects, your application should use a paged query by also using the <code>skip</code> URL parameter. You will see an example of this below.
<p class="alert"> Note that your application may experience strange behavior with large limits, such as ?limit=1000. It is recommended to use a limit of 100 or less. If you expect there are more than 100 matching records, use a paged query to make consecutive requests until all records all gathered.</p>
</p>
<p>
<div class="exHeading">Non-Paged Query Javascript Example</div>
<pre><code class="jsExample">
<span>const matched_objects = await fetch("https://devstore.rerum.io/v1/api/query", {</span>
<span class="ind1">method: "POST",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify(</span>
<span class="ind2">{"type": "Object", "shape": "round"}</span>
<span class="ind1">)</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>[</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind2">"type": "Object",</span>
<span class="ind2">"shape": "round",</span>
<span class="ind2">"name": "Ball",</span>
<span class="ind2">"__rerum":{...}</span>
<span class="ind1">},</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/1234567890abcdef",</span>
<span class="ind2">"type": "Object",</span>
<span class="ind2">"shape": "round",</span>
<span class="ind2"> "name": "Globe",</span>
<span class="ind2">"__rerum":{...}</span>
<span class="ind1">},</span>
<span class="ind1">...</span>
<span>]</span>
</code></pre>
<p class="alert">
All responses are a JSON Array that is not ordered, even if a single or zero records are matched.
</p>
</p>
<p>
<div class="exHeading">Paged Query Javascript Example</div>
<pre><code class="jsExample">
<span>const many_results = await pagedQuery(100, 0, {"type": "Thing"})</span>
<br>
<span>function pagedQuery(lim, it = 0, queryObj, allResults = []) {</span>
<span class="ind1">return fetch(`https://devstore.rerum.io/v1/api/query?limit=${lim}&skip=${it}`, {</span>
<span class="ind2"> method: "POST",</span>
<span class="ind2">headers: {</span>
<span class="ind3">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind2">},</span>
<span class="ind2">body: JSON.stringify(queryObj)</span>
<span class="ind1">})</span>
<span class="ind1">.then(response => response.json())</span>
<span class="ind1">.then(results => {</span>
<span class="ind2">if (results.length) {</span>
<span class="ind3">allResults = allResults.concat(results)</span>
<span class="ind3">return pagedQuery(lim, it + results.length, queryObj, allResults)</span>
<span class="ind2">}</span>
<span class="ind2">return allResults</span>
<span class="ind1">})</span>
<span class="ind1">.catch(err => {</span>
<span class="ind2">console.warn("Could not process a result in paged query")</span>
<span class="ind2">throw err</span>
<span class="ind1">})</span>
<span>}</span>
</code></pre>
</p>
<h3 id="http-post-method-override">HTTP POST Method Override</h3>
<p class="alert"> This section is non-normative. </p>
<p>
Some programming languages and some servers do not consider <code
class="language-plaintext highlighter-rouge">PATCH</code> to be a standard method.
As a result, some software is unable to make a <code
class="language-plaintext highlighter-rouge">PATCH</code> update request directly.
RERUM still wants these applications to fit within these standards. We support
the <code class="language-plaintext highlighter-rouge">X-HTTP-Method-Override</code> header on <code
class="language-plaintext highlighter-rouge">POST</code> requests to make them act like <a
href="#patch-update"><code class="language-plaintext highlighter-rouge">PATCH</code> requests
in this API</a>.
</p>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/patch</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code
class="language-plaintext highlighter-rouge">Location: https://devstore.rerum.io/v1/id/1234567890abcdef</code>
<code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The record to patch
update.</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—Containing
various bits of information about the patch.</li>
</ul>
<p>Example Method Override Request:</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const patched_obj = await fetch("https://devstore.rerum.io/v1/api/patch", {</span>
<span class="ind1">method: "POST",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"X-HTTP-Method-Override": "PATCH",</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw",</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify(</span>
<span class="ind2">{</span>
<span class="ind3">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"existing_property": "new_value"</span>
<span class="ind2">}</span>
<span class="ind1">)</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p class="alert">
See the Patch Update section for details on the response <code>resp</code>.
</p>
<h2 id="put">PUT</h2>
<p class="alert">
The <code class="language-plaintext highlighter-rouge">__rerum</code>, <code
class="language-plaintext highlighter-rouge">@id</code> and <code
class="language-plaintext highlighter-rouge">_id</code> properties are ignored on all PUT requests.
</p>
<p class="warning">Updates to released or deleted records fail with an error.</p>
<h3 id="update">Update</h3>
<p>
Replace an existing record through reference to its internal RERUM id and receive the <code class="language-plaintext highlighter-rouge">Location</code> URI for the resulting record as a response header and the complete record as the response body.
This will have the effects of update, set, and unset actions.
New keys will be created and keys not present in the request will not be present in the resulting record.
When an object is updated, the <code class="language-plaintext highlighter-rouge">@id</code> will change.
This results in the need to track history and the previous version will be represented in the <code class="language-plaintext highlighter-rouge">__rerum.history.previous</code> of the resulting record.
</p>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/update</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code
class="language-plaintext highlighter-rouge">Location: https://devstore.rerum.io/v1/id/1234567890abcdef</code>
<code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The requested new
state for the record.</li>
<li><strong>Response Body: <code
class="language-plaintext highlighter-rouge">{JSON}</code></strong>—Containing various bits of
information about the PUT update.</li>
</ul>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const updated = await fetch("https://devstore.rerum.io/v1/api/update", {</span>
<span class="ind1">method: "PUT",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw",</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify(</span>
<span class="ind2">{</span>
<span class="ind3">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"be": "kind"</span>
<span class="ind2">}</span>
<span class="ind1">)</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>{</span>
<span class="ind1">"@id": "https://devstore.rerum.io/v1/id/1234567890abcdef",</span>
<span class="ind1">"be": "kind",</span>
<span class="ind1">"__rerum":{</span>
<span class="ind2">...</span>
<span class="ind2">"history":{</span>
<span class="ind3">"next": [],</span>
<span class="ind3">"previous": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"prime": "https://devstore.rerum.io/v1/id/abcdef1234567890"</span>
<span class="ind2">}</span>
<span class="ind1">}</span>
<span>}</span>
</code></pre>
<p class="alert">
Note that resp.headers.get("location") will return "https://devstore.rerum.io/v1/id/1234567890abcdef"
</p>
<p class="alert">
Note that the original record "https://devstore.rerum.io/v1/id/abcdef1234567890" now has
<code>
__rerum.history.next : ["https://devstore.rerum.io/v1/id/1234567890abcdef"]
</code>
</p>
</p>
<h3 id="bulk-update">Bulk Update</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/bulkUpdate</code></td>
<td><code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
<td>200 <code>
<code class="language-plaintext highlighter-rouge">[{JSON}]</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array RERUM objects
to be updated.</li>
<li><strong>Response: <code class="language-plaintext highlighter-rouge">[{JSON}]</code></strong>—an array
of the resolved records from the update process</li>
</ul>
<p>
Update multiple existing RERUM objects at once and recieve an array of the complete records as the response body.
Accepts only a single array of JSON objects in the request body. The '@id' property must be present for each object.
In cases where the Linked Data @context property maps '@id' to 'id' either of these properties will be sufficient.
The array of JSON objects passed in may not be updated in the order submitted. The response will have the URI
of the new resource or an error message as an array in the order the objects were processed. When errors are encountered, the batch process will attempt to continue for all submitted items.
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const updated_objs = await fetch("https://devstore.rerum.io/v1/api/bulkUpdate", {</span>
<span class="ind1">method: "PUT",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw" </span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">body: JSON.stringify([{
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind2">"hello": "new world"</span>
<span class="ind1">},</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/1234567890abcdef",</span>
<span class="ind2">"goodbye": "old planet"</span>
<span class="ind1">}])</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>[</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/abcabc1231231230",</span>
<span class="ind2">"hello": "new world",</span>
<span class="ind2">"__rerum":{...}</span>
<span class="ind1">},</span>
<span class="ind1">{</span>
<span class="ind2">"@id": "https://devstore.rerum.io/v1/id/defdef4564564567",</span>
<span class="ind2">"goodbye": "old planet",</span>
<span class="ind2"> "__rerum":{...}</span>
<span class="ind1">}</span>
<span>]</span>
</code></pre>
</p>
<h3 id="overwrite">Overwrite</h3>
<p>
RERUM allows the Generator of a record to overwrite that record. An error will be returned if the agent encoded in the request "Authorization" access token does not match the <code __rerum.generatedBy></code> agent of the existing record. </span>
Replace a record using a reference to its internal RERUM id and receive the <code class="language-plaintext highlighter-rouge">Location</code> URI for the resulting record as a response header and the complete record as the response body.
This will have the effects of update, set, and unset actions. New keys will be created and keys not present in the request will not be present in the resulting record.
The record is replaced in place, or overwritten, and so the <code class="language-plaintext highlighter-rouge">@id</code> will not change and the history connected with this record will not be altered. The <code>__rerum.isOverwritten</code> property will be set to the date and time of the overwrite.
</p>
<p>
This endpoint supports optimistic locking, if requested. Including the "If-Overwritten-Version" header with the
value of the <code class="language-plaintext highlighter-rouge">__rerum.isOverwritten</code> property of the
record will cause the request to fail if the record has been overwritten since that time.
This is useful for preventing overwriting a record that has been changed by another agent, colliding within an
application that rapidly requests overwrites of the same object, or if an object is held in memory or cache for a
long time prior to the overwrite. Omitting the "If-Overwritten-Version" header or <code class="language-plaintext highlighter-rouge">__rerum.isOverwritten</code>
property will cause the request to succeed regardless.
</p>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/overwrite</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code
class="language-plaintext highlighter-rouge">Location: https://devstore.rerum.io/v1/id/abcdef1234567890</code>
<code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The requested new
state for the record.</li>
<li><strong>Response Body: <code
class="language-plaintext highlighter-rouge">{JSON}</code></strong>—Containing various bits of
information about the PUT overwrite.</li>
</ul>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const overwritten = await fetch("https://devstore.rerum.io/v1/api/overwrite", {</span>
<span class="ind1">method: "PUT",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw",</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify(</span>
<span class="ind2">{</span>
<span class="ind3">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"be": "kind"</span>
<span class="ind2">}</span>
<span class="ind1">)</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p class="alert">
In the case of an optimistic locking failure, the response will be a 409 Conflict with a
body containing the current version of the document, in case you would like to automate a
retry of the overwrite request.
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>{</span>
<span class="ind1">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind1">"be": "kind",</span>
<span class="ind1">"__rerum":{</span>
<span class="ind2">...</span>
<span class="ind2">"isOverwritten": "2023-07-19T19:06:24.030"</span>
<span class="ind1">}</span>
<span>}</span>
</code></pre>
<p class="alert">
Note: resp.headers.get("location") will return "https://devstore.rerum.io/v1/id/abcdef1234567890"
</p>
<p class="alert">
Note: the <code>@id</code> and <code>__rerum.history</code> properties of the original record "https://devstore.rerum.io/v1/id/abcdef1234567890" have not changed. This is the difference between /update and /overwrite. Be careful.
</p>
</p>
<!--
<h3 id="bulk-update-beta">Bulk Update (beta)</h3>
<p class="alert">
Note that Bulk Update is under development and is not yet available.
</p>
-->
<h2 id="patch">PATCH</h2>
<p class="alert">
The <code class="language-plaintext highlighter-rouge">__rerum</code>, <code
class="language-plaintext highlighter-rouge">@id</code> and <code
class="language-plaintext highlighter-rouge">_id</code> properties are ignored on all PATCH requests.
</p>
<p class="warning">Updates to released or deleted records fail with an error.</p>
<h3 id="patch-update">Patch Update</h3>
<table>
<thead>
<tr>
<th>Patterns</th>
<th>Payloads</th>
<th>Responses</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="language-plaintext highlighter-rouge">/patch</code></td>
<td><code class="language-plaintext highlighter-rouge">{JSON}</code></td>
<td>200 <code
class="language-plaintext highlighter-rouge">Location: https://devstore.rerum.io/v1/id/1234567890abcdef</code>
<code class="language-plaintext highlighter-rouge">{JSON}</code></td>
</tr>
</tbody>
</table>
<ul>
<li><strong><code class="language-plaintext highlighter-rouge">{JSON}</code></strong>—The requested new
state for the record. MUST contain an <code class="language-plaintext highlighter-rouge">@id</code></li>
<li><strong>Response Body: <code
class="language-plaintext highlighter-rouge">{JSON}</code></strong>—Containing various bits of
information about the PATCH update.</li>
</ul>
<p>
A single record is updated by altering the set or subset of existing properties on the targeted RERUM record.
This method only manipulates existing record properties. Unmatched properties are ignored and will not appear
on the resulting patched record.
If <code class="language-plaintext highlighter-rouge">{"key":null}</code> is submitted,
the value for property "key" will be set to <code class="language-plaintext highlighter-rouge">null</code> instead of removing the property.
This results in the need to track history and the previous version will be represented in the <code class="language-plaintext highlighter-rouge">__rerum.history.previous</code> of the resulting record.
</p>
<p>
<div class="exHeading">Javascript Example</div>
<pre><code class="jsExample">
<span>const patched_obj = await fetch("https://devstore.rerum.io/v1/api/patch", {</span>
<span class="ind1">method: "PATCH",</span>
<span class="ind1">headers:{</span>
<span class="ind2">"Authorization": "Bearer eyJz93a...k4laUWw",</span>
<span class="ind2">"Content-Type": "application/json; charset=utf-8"</span>
<span class="ind1">},</span>
<span class="ind1">body: JSON.stringify(</span>
<span class="ind2">{</span>
<span class="ind3">"@id": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"existing_property": "new_value",</span>
<span class="ind3">"unmatched_property": "will be ignored"</span>
<span class="ind2">}</span>
<span class="ind1">)</span>
<span>})</span>
<span>.then(resp => resp.json())</span>
<span>.catch(err => {throw err})</span>
</code></pre>
</p>
<p>
<div class="exHeading">Here is what the response <code>resp</code> looks like:</div>
<pre><code class="respExample">
<span>{</span>
<span class="ind1">"@id": "https://devstore.rerum.io/v1/id/1234567890abcdef",</span>
<span class="ind1">"existing_property": "new_value",</span>
<span class="ind1">"__rerum":{</span>
<span class="ind2">...</span>
<span class="ind2">"history":{</span>
<span class="ind3">"next": [],</span>
<span class="ind3">"previous": "https://devstore.rerum.io/v1/id/abcdef1234567890",</span>
<span class="ind3">"prime": "https://devstore.rerum.io/v1/id/abcdef1234567890"</span>
<span class="ind2">}</span>
<span class="ind1">}</span>
<span>}</span>
</code></pre>
<p class="alert">
Note that resp.headers.get("location") will return "https://devstore.rerum.io/v1/id/1234567890abcdef"</span>
</p>
<p class="alert">
Note that the original record "https://devstore.rerum.io/v1/id/abcdef1234567890" now has</span>
<code>