-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresentation1.html
More file actions
758 lines (757 loc) · 40.1 KB
/
presentation1.html
File metadata and controls
758 lines (757 loc) · 40.1 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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<meta name="author" content="R. S. Doiel, [email protected]" />
<meta name="date" content="2025-06-12" />
<meta name="keywords" content="Dataset, HTML, JavaScript, Web
Components" />
<title>A recipe for applications: Dataset & Web Components</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
/* The extra [class] is a hack that increases specificity enough to
override a similar rule in reveal.js */
ul.task-list[class]{list-style: none;}
ul.task-list li input[type="checkbox"] {
font-size: inherit;
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
/* CSS for syntax highlighting */
html { -webkit-text-size-adjust: 100%; }
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" type="text/css" media="screen, projection, print"
href="./styles/slidy.css" />
<link rel="stylesheet" type="text/css" media="screen, projection, print"
href="styles/sea-and-shore.css" />
<script src="./scripts/slidy.js"
charset="utf-8" type="text/javascript"></script>
</head>
<body>
<div class="slide titlepage">
<h1 class="title">A recipe for applications: Dataset & Web
Components</h1>
<p class="author">
R. S. Doiel, <a href="mailto:[email protected]"
class="email">[email protected]</a>
</p>
<p class="institute">
<p>Caltech Library, Digital Library Development</p>
</p>
<p class="date">2025-06-12</p>
</div>
<div class="slide" id="TOC">
</div>
<div id="welcome-to-a-recipe-for-applications"
class="slide section level1">
<h1>Welcome to “A recipe for applications”</h1>
<p>Welcome everyone. This is a hands on workshop (part 1).</p>
<blockquote>
<p>An approach to building web applications using Dataset</p>
</blockquote>
</div>
<div id="workshop-dataset-html" class="slide section level1">
<h1>Workshop: Dataset & HTML</h1>
<h2 id="what-well-do">What we’ll do</h2>
<ul>
<li>We’ll build a web application for managing a list of recipes</li>
<li>Work with HTML, a little JavaScript, JSON and YAML</li>
</ul>
</div>
<div id="workshop-dataset-html-1" class="slide section level1">
<h1>Workshop: Dataset & HTML</h1>
<h2 id="what-well-learn">What we’ll learn</h2>
<ul>
<li>How to create a JSON API using a YAML file and an embedded SQL
SELECT statement</li>
<li>How to use HTML and a little JavaScript browser to turn the API into
an application</li>
</ul>
<p>Follow along at <a
href="https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html"
class="uri">https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html</a></p>
<p>Download the presentation zip file at <a
href="https://github.com/caltechlibrary/t2t3_dataset_web_apps/releases"
class="uri">https://github.com/caltechlibrary/t2t3_dataset_web_apps/releases</a></p>
</div>
<div id="getting-started" class="slide section level1">
<h1>Getting started</h1>
<h3 id="you-probably-already-have-these-if-not-install-them">You
probably already have these, if not install them</h3>
<ul>
<li>A computer running macOS, Linux, Raspberry Pi OS, Windows</li>
<li>Terminal application</li>
<li><a href="https://vscodium.com/">Text Editor</a></li>
<li><a href="https://www.mozilla.org/en-US/firefox/new/">Web Browser</a>
(I’m assuming Firefox for this tutorial)</li>
<li><a href="https://curl.se/">cURL</a> (macOS/Linux) or <a
href="https://learn.microsoft.com/en-us/powershell/module/?term=irm">irm</a>
(Windows)</li>
</ul>
</div>
<div id="getting-started-1" class="slide section level1">
<h1>Getting started</h1>
<h3 id="install-dataset">Install dataset</h3>
<ul>
<li>See <a href="https://caltechlibrary.github.io/dataset/INSTALL.html"
class="uri">https://caltechlibrary.github.io/dataset/INSTALL.html</a>
<ul>
<li>If you have problems you can download the zip files from here <a
href="https://github.com/caltechlibrary/dataset/releases"
class="uri">https://github.com/caltechlibrary/dataset/releases</a></li>
</ul></li>
<li>You need to be running the latest v2 release (>= 2.3.2)</li>
</ul>
<p>NOTE: <a
href="https://caltechlibrary.github.io/dataset/INSTALL_NOTES_macOS.html">INSTALL
NOTES macOS</a> & <a
href="https://caltechlibrary.github.io/dataset/INSTALL_NOTES_Windows.html">INSTALL
NOTES Windows</a></p>
<p>We can start our first iteration of our application once you have
these available.</p>
</div>
<div id="wait-what-is-dataset" class="slide section level1">
<h1>Wait, what is Dataset?</h1>
<h2 id="short-answer">Short answer</h2>
<ul>
<li>A collection of tools for curating JSON objects as collections</li>
</ul>
</div>
<div id="wait-what-is-dataset-1" class="slide section level1">
<h1>Wait, what is Dataset?</h1>
<h2 id="long-answer">Long answer</h2>
<ul>
<li>A way of managing collections of JSON documents
<ul>
<li>A JSON document expresses an object, e.g. a metadata record</li>
</ul></li>
<li>Dataset manages objects using key object pairs</li>
<li>The JSON objects can be queried using SQL</li>
<li>Collections are flexible (schema-less)</li>
</ul>
</div>
<div id="part-1-what-are-we-building" class="slide section level1">
<h1>Part 1: What are we building?</h1>
<p>GOAL: A simple web application that lets us curate a list of
recipes.</p>
<ul>
<li>Start with the web service (back end)</li>
<li>Finish with the browser (front end, browser side)</li>
</ul>
</div>
<div id="part-1.1-what-are-the-parts-of-our-application"
class="slide section level1">
<h1>Part 1.1: What are the parts of our application?</h1>
<ol style="list-style-type: decimal">
<li>A web service for managing the recipe collection</li>
<li>A page to browse recipes by name</li>
<li>A page to display a recipe</li>
<li>A page with a web form to add or edit a recipe</li>
</ol>
</div>
<div id="part-1.1-what-is-a-recipe-its-data-structure"
class="slide section level1">
<h1>Part 1.1: What is a recipe? (it’s data structure)</h1>
<ul>
<li>A “key”, the unique identifier of a recipe (url friendly)</li>
<li>A name (human friendly and readable)</li>
<li>A list of ingredients and their quantities (CSV data)</li>
<li>A procedure describing the preparation process (text)</li>
</ul>
</div>
<div id="part-1.1-basic-strategy" class="slide section level1">
<h1>Part 1.1: Basic Strategy</h1>
<ol style="list-style-type: decimal">
<li>Setting up a collection</li>
<li>Setting up our web service</li>
<li>Sketch our app using HTML</li>
<li>Wire up and test</li>
</ol>
</div>
<div id="part-1.2-setting-up-our-collection"
class="slide section level1">
<h1>Part 1.2: Setting up our collection</h1>
<ol style="list-style-type: decimal">
<li>create our <code>recipes.ds</code> collection</li>
<li>load sample data into our <code>recipes.ds</code> collection</li>
<li>Configure and run our collection web service</li>
</ol>
</div>
<div id="part-1.2-creating-our-collection" class="slide section level1">
<h1>Part 1.2: creating our collection</h1>
<p>We use the <code>dataset</code> command line program to initialize a
dataset collection.</p>
<pre class="shell"><code>dataset init recipes.ds</code></pre>
<p>(Linux, macOS and Windows)</p>
</div>
<div id="part-1.2-sample-data-its-nice-to-have"
class="slide section level1">
<h1>Part 1.2: Sample Data, it’s nice to have</h1>
<ul>
<li>When prototyping applications it’s nice to have data to work
with</li>
<li>I’ve created some for our recipe application</li>
<li>Dataset supports ingesting collections using JSON line
documents</li>
</ul>
</div>
<div id="part-1.2-what-is-json-lines" class="slide section level1">
<h1>Part 1.2: What is JSON Lines?</h1>
<ul>
<li>Sometimes called JSON-L, JSONL, file extension
<code>.jsonl</code></li>
<li>One JSON object per line, see <a href="https://jsonlines.org/"
class="uri">https://jsonlines.org/</a></li>
<li>A portable way to express object collections
<ul>
<li>supported by dataset’s dump and load actions</li>
</ul></li>
</ul>
</div>
<div id="part-1.2-loading-some-sample-data"
class="slide section level1">
<h1>Part 1.2: Loading some sample data</h1>
<p>Download sample data file <a
href="recipes.jsonl">recipes.jsonl</a></p>
<pre class="shell"><code>curl -o recipes.jsonl \
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes.jsonl
cat recipes.jsonl | dataset load recipes.ds</code></pre>
<p>On Windows:</p>
<pre class="pwsh"><code>irm -OutFile recipes.jsonl `
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes.jsonl
Get-Content recipes.jsonl | dataset load recipes.ds</code></pre>
</div>
<div id="part-1.2-verify-we-loaded-our-data-ok"
class="slide section level1">
<h1>Part 1.2: Verify we loaded our data OK</h1>
<pre class="shell"><code>dataset keys recipes.ds
dataset read recipes.ds frybread</code></pre>
</div>
<div id="part-1.2-example-terminal-interaction"
class="slide section level1">
<h1>Part 1.2: Example terminal interaction</h1>
<pre class="shell"><code>$ dataset keys recipes.ds
blondies
brownies
cafe-con-leche
frybread
poi
waffles</code></pre>
</div>
<div id="part-1.2-example-terminal-interaction-1"
class="slide section level1">
<h1>Part 1.2: Example terminal interaction</h1>
<pre class="shell"><code>$ dataset read recipes.ds frybread
{
"ingredients": "backing powder,2 tsp\r\nflour,2 cups\r\nhot water,2/3 cups\r\nsalt,1 tsp salt\r\nshortening,2 Tbsp\r\n",
"key": "frybread",
"name": "Fry Bread",
"procedure": "1. Combine flour, baking powder, and salt in a bowl.\r\n2. Use a pastry blender (or two butter knives) to cut the shortening into the flour.\r\n3. Add the hot water, and mix until the water is incorporated and you get a dough.\r\n4. Turn out the dough on a lightly floured board. Knead the dough until it is soft and smooth.\r\n5. Wrap the dough in plastic, and let the dough rest for 30 minutes.\r\n6. Divide the dough into 6 pieces, roll each into a ball, and roll each into a flat disk with a rolling pin.\r\n7. Brush one side of each disk with melted margarine and place on a barbecue over a 3 Mississippi fire.\r\n8. Brush the opposing side of the bread with margarine and flip the bread on the barbecue.\r\n9. Cook until both sides are golden brown. Serve hot.\r\n\r\n- You can substitute either 1/4 cup plain yogurt, or a 1/4 cup soured milk as a leavening agent\r\ninstead of baking powder. If you do, add 2 hours to the rest time for the dough, and leave\r\nthe dough somewhere warm. You can optionally include the baking powder as well to get a\r\nvery puffy version of frybread. If using yogurt or soured milk for leavening, use 1\2 cup\r\ninstead of 1/3 cup water.\r\n- You can use mayonnaise in place of shortening for a crispy, crunchier texture.\r\n- You can also fry the dough in hot oil over a stove top. The dough cooks rapidly and will brown\r\nin about 12 seconds and must be turned over to allow the opposite side to brown, then be removed\r\nfrom the oil and placed sideways into a colander or large bowl lined with paper towels to allow\r\nthe oil to drain off the finished product\r\n\r\nurl: https://en.wikibooks.org/wiki/Cookbook:Fry_Bread_I\r\n"
}</code></pre>
</div>
<div id="part-1.2-setting-up-our-web-service"
class="slide section level1">
<h1>Part 1.2: Setting up our web service</h1>
<ol style="list-style-type: decimal">
<li>Create our static content directories</li>
<li>Define our web service using a YAML file</li>
</ol>
</div>
<div id="part-1.2-create-the-static-content-directories"
class="slide section level1">
<h1>Part 1.2: create the static content directories</h1>
<pre class="shell"><code>mkdir htdocs
mkdir htdocs/css
mkdir htdocs/modules</code></pre>
</div>
<div id="part-1.2-dataset-stores-our-objects-how-does-that-help"
class="slide section level1">
<h1>Part 1.2: Dataset stores our objects, how does that help?</h1>
<ul>
<li>The Dataset project provides a web service called
<code>datasetd</code></li>
<li>This web service provides a <a
href="https://en.wikipedia.org/wiki/REST">REST</a> JSON API for one or
more dataset collections</li>
<li>Dataset web service can provide static content hosting</li>
<li>These two features implement a “back end” for a web application</li>
</ul>
</div>
<div id="part-1.2-setting-up-our-web-service-1"
class="slide section level1">
<h1>Part 1.2: Setting up our web service</h1>
<p><code>datasetd</code> web service is defined by a simple YAML file.
It has three top level attributes</p>
<ul>
<li>host (required)</li>
<li>htdocs (optional)</li>
<li>collections (optional)</li>
</ul>
<p>NOTE: Dataset web service can host many collections at the same
time.</p>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>YAML is a superset of JSON that is easy to read and easy to type.</p>
<ol style="list-style-type: decimal">
<li>Create a file, using your text editor called <a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes_api.yaml">recipes_api.yaml</a></li>
<li>Type in <code>host: localhost:8001</code></li>
</ol>
<div class="sourceCode" id="cb8"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span></code></pre></div>
<p>This line tells dataset web service that it should listen on port
8001 on localhost. Dataset web services always run on localhost.</p>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file-1"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>Since we are going to build a web application we need to tell the
Dataset web service where to find our static content. This is done using
the <code>htdocs</code> attribute. Relative paths are assumed to start
at the same directory level as our YAML file. Add our htdocs line based
on the directory structure we created earlier.</p>
<div class="sourceCode" id="cb9"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb9-1"><a href="#cb9-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb9-2"><a href="#cb9-2" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span></code></pre></div>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file-2"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>The next element, <code>collections</code> lets us define a list of
one or more dataset collections that are available from our web service.
For our project we define just one. Our collection is called,
<code>recipes.ds</code>.</p>
<div class="sourceCode" id="cb10"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb10-1"><a href="#cb10-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb10-2"><a href="#cb10-2" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span>
<span id="cb10-3"><a href="#cb10-3" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb10-4"><a href="#cb10-4" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> recipes</span></span></code></pre></div>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file-3"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>We now have a minimal configuration. But right now it is not useful.
For each collection we need to define the access (at the collection
level) needed by our web application. The access is modeled on the core
actions available in the dataset command line tool.</p>
<ul>
<li>keys (allow retrieval of keys)</li>
<li>create (allow objects to be added to a collection)</li>
<li>update (allow objects in a collection to be updated)</li>
<li>delete (allow objects to be deleted)</li>
</ul>
<p>If an permission is not included it is defaults to false. The value
true will enabled it.</p>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file-4"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>Here’s what the permissions look like for our web application.</p>
<div class="sourceCode" id="cb11"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb11-1"><a href="#cb11-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb11-2"><a href="#cb11-2" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span>
<span id="cb11-3"><a href="#cb11-3" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb11-4"><a href="#cb11-4" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> recipes</span></span>
<span id="cb11-5"><a href="#cb11-5" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb11-6"><a href="#cb11-6" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb11-7"><a href="#cb11-7" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb11-8"><a href="#cb11-8" tabindex="-1"></a><span class="at"> </span><span class="fu">delete</span><span class="kw">:</span><span class="at"> </span><span class="ch">false</span></span></code></pre></div>
</div>
<div id="part-1.2-we-need-to-create-our-yaml-configuration-file-5"
class="slide section level1">
<h1>Part 1.2: We need to create our YAML configuration file</h1>
<p>SQL is a powerful language. Dataset only allows defined queries to be
run. One simple query is needed for our application,
<code>index_recipes</code>.</p>
<div class="sourceCode" id="cb12"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> recipes</span></span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb12-8"><a href="#cb12-8" tabindex="-1"></a><span class="at"> </span><span class="fu">delete</span><span class="kw">:</span><span class="at"> </span><span class="ch">false</span></span>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a><span class="at"> </span><span class="fu">query</span><span class="kw">:</span></span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a><span class="fu"> list_recipes</span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb12-11"><a href="#cb12-11" tabindex="-1"></a> select src</span>
<span id="cb12-12"><a href="#cb12-12" tabindex="-1"></a> from recipes</span>
<span id="cb12-13"><a href="#cb12-13" tabindex="-1"></a> order by src->>'name'</span></code></pre></div>
</div>
<div id="part-1.2-rest-and-the-browser" class="slide section level1">
<h1>Part 1.2: REST and the browser</h1>
<ul>
<li>The dataset web service is a REST JSON API</li>
<li>Browsers do not support REST in HTML (only GET and POST)</li>
</ul>
</div>
<div id="part-1.2-rest-and-the-browser-1" class="slide section level1">
<h1>Part 1.2: REST and the browser</h1>
<ul>
<li>Dataset web service overloads POST to subsume PUT actions of
REST</li>
<li>Dataset web service supports success and error redirects for
POST</li>
</ul>
<div class="sourceCode" id="cb13"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb13-1"><a href="#cb13-1" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb13-2"><a href="#cb13-2" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span>
<span id="cb13-3"><a href="#cb13-3" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb13-4"><a href="#cb13-4" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> recipes</span></span>
<span id="cb13-5"><a href="#cb13-5" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb13-6"><a href="#cb13-6" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb13-7"><a href="#cb13-7" tabindex="-1"></a><span class="co"> # Create redirects do double duty as a POST also supports update.</span></span>
<span id="cb13-8"><a href="#cb13-8" tabindex="-1"></a><span class="at"> </span><span class="fu">create_success</span><span class="kw">:</span><span class="at"> http://localhost:8001/display_recipe.html</span></span>
<span id="cb13-9"><a href="#cb13-9" tabindex="-1"></a><span class="at"> </span><span class="fu">create_error</span><span class="kw">:</span><span class="at"> http://localhost:8001/edit_recipe.html</span></span>
<span id="cb13-10"><a href="#cb13-10" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb13-11"><a href="#cb13-11" tabindex="-1"></a><span class="at"> </span><span class="fu">delete</span><span class="kw">:</span><span class="at"> </span><span class="ch">false</span></span>
<span id="cb13-12"><a href="#cb13-12" tabindex="-1"></a><span class="at"> </span><span class="fu">query</span><span class="kw">:</span></span>
<span id="cb13-13"><a href="#cb13-13" tabindex="-1"></a><span class="fu"> list_recipes</span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb13-14"><a href="#cb13-14" tabindex="-1"></a> select src</span>
<span id="cb13-15"><a href="#cb13-15" tabindex="-1"></a> from recipes</span>
<span id="cb13-16"><a href="#cb13-16" tabindex="-1"></a> order by src->>'name'</span></code></pre></div>
</div>
<div id="part-1.2-recipes_api.yaml" class="slide section level1">
<h1>Part 1.2: recipes_api.yaml</h1>
<p>YAML allows comments, here’s an example.</p>
<div class="sourceCode" id="cb14"><pre
class="sourceCode yaml"><code class="sourceCode yaml"><span id="cb14-1"><a href="#cb14-1" tabindex="-1"></a><span class="co">#!/usr/bin/env -S datasetd -debug</span></span>
<span id="cb14-2"><a href="#cb14-2" tabindex="-1"></a><span class="co"># Host and port to listen on</span></span>
<span id="cb14-3"><a href="#cb14-3" tabindex="-1"></a><span class="fu">host</span><span class="kw">:</span><span class="at"> localhost:8001</span></span>
<span id="cb14-4"><a href="#cb14-4" tabindex="-1"></a><span class="co"># location of our static content</span></span>
<span id="cb14-5"><a href="#cb14-5" tabindex="-1"></a><span class="fu">htdocs</span><span class="kw">:</span><span class="at"> htdocs</span></span>
<span id="cb14-6"><a href="#cb14-6" tabindex="-1"></a><span class="co"># Define the collections supported in our application</span></span>
<span id="cb14-7"><a href="#cb14-7" tabindex="-1"></a><span class="fu">collections</span><span class="kw">:</span></span>
<span id="cb14-8"><a href="#cb14-8" tabindex="-1"></a><span class="co"> # Define the permissions and behavior of the API For our recipe collection</span></span>
<span id="cb14-9"><a href="#cb14-9" tabindex="-1"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="fu">dataset</span><span class="kw">:</span><span class="at"> recipes.ds</span></span>
<span id="cb14-10"><a href="#cb14-10" tabindex="-1"></a><span class="at"> </span><span class="fu">keys</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb14-11"><a href="#cb14-11" tabindex="-1"></a><span class="at"> </span><span class="fu">create</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb14-12"><a href="#cb14-12" tabindex="-1"></a><span class="co"> # When we successfully create or update via a form using a POST method</span></span>
<span id="cb14-13"><a href="#cb14-13" tabindex="-1"></a><span class="co"> # display the updated object</span></span>
<span id="cb14-14"><a href="#cb14-14" tabindex="-1"></a><span class="at"> </span><span class="fu">create_success</span><span class="kw">:</span><span class="at"> http://localhost:8001/display_recipe.html</span></span>
<span id="cb14-15"><a href="#cb14-15" tabindex="-1"></a><span class="co"> # When we fail go back to the current page.</span></span>
<span id="cb14-16"><a href="#cb14-16" tabindex="-1"></a><span class="at"> </span><span class="fu">create_error</span><span class="kw">:</span><span class="at"> http://localhost:8001/edit_recipe.html</span></span>
<span id="cb14-17"><a href="#cb14-17" tabindex="-1"></a><span class="at"> </span><span class="fu">read</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb14-18"><a href="#cb14-18" tabindex="-1"></a><span class="at"> </span><span class="fu">update</span><span class="kw">:</span><span class="at"> </span><span class="ch">true</span></span>
<span id="cb14-19"><a href="#cb14-19" tabindex="-1"></a><span class="at"> </span><span class="fu">delete</span><span class="kw">:</span><span class="at"> </span><span class="ch">false</span></span>
<span id="cb14-20"><a href="#cb14-20" tabindex="-1"></a><span class="at"> </span><span class="fu">query</span><span class="kw">:</span></span>
<span id="cb14-21"><a href="#cb14-21" tabindex="-1"></a><span class="fu"> list_recipes</span><span class="kw">: </span><span class="ch">|</span></span>
<span id="cb14-22"><a href="#cb14-22" tabindex="-1"></a> select src</span>
<span id="cb14-23"><a href="#cb14-23" tabindex="-1"></a> from recipes</span>
<span id="cb14-24"><a href="#cb14-24" tabindex="-1"></a> order by src->>'name'</span></code></pre></div>
</div>
<div id="part-1.2-recipes_api.yaml-1" class="slide section level1">
<h1>Part 1.2: recipes_api.yaml</h1>
<p>On macOS and Linux you can cURL the <code>recipes_api.yaml</code>
using the following statement.</p>
<pre class="shell"><code>curl -o recipes_api.yaml \
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes_api.yaml</code></pre>
<p>On Windows</p>
<pre class="pwsh"><code>irm -OutFile recipes_api.yaml `
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes_api.yaml</code></pre>
</div>
<div id="part-1.2-starting-and-stopping-the-web-service"
class="slide section level1">
<h1>Part 1.2: Starting and stopping the web service</h1>
<p>Starting the web service.</p>
<pre class="shell"><code>datasetd -debug recipes_api.yaml</code></pre>
<ul>
<li>Go do <a href="http://localhost:8001/api/version"
class="uri">http://localhost:8001/api/version</a></li>
<li>Look at the terminal window, do you see the log message for the
request?</li>
<li>You can shutdown the service by press control and C (Ctrl-C) in the
terminal session</li>
</ul>
</div>
<div id="part-1.2-starting-and-stopping-the-web-service-1"
class="slide section level1">
<h1>Part 1.2: Starting and stopping the web service</h1>
<ul>
<li>Tired to typing
“<code>datasetd -debug recipes_api.yaml</code>”?</li>
<li>Make the YAML file executable!</li>
</ul>
<p>(on macOS, Linux or Window’s WSL)</p>
<pre class="shell"><code>chmod 775 recipes_api.yaml</code></pre>
<p>Now you can shorten start up to</p>
<pre class="shell"><code>./recipes_api.yaml</code></pre>
</div>
<div id="part-1.3-what-about-our-static-content"
class="slide section level1">
<h1>Part 1.3: What about our static content?</h1>
<p>The web service is running but the htdocs directory is not
populated.</p>
<p>What do you see when you go to <a href="http://localhost:8001/"
class="uri">http://localhost:8001/</a>?</p>
<p>We can complete our application by building the front end with HTML,
CSS and JavaScript.</p>
</div>
<div id="part-1.3-what-should-our-recipe-metadata-look-like"
class="slide section level1">
<h1>Part 1.3: What should our recipe metadata look like?</h1>
<dl>
<dt>key</dt>
<dd>
A unique identifier for the recipe (needed by dataset to distinguish
objects).
</dd>
<dt>name</dt>
<dd>
A line of text. Held by an <code>input</code> element
</dd>
<dt>ingredients</dt>
<dd>
A CSV table. Held by a <code>textarea</code> or for display a
<code>table</code>.
</dd>
<dt>procedure</dt>
<dd>
Free text describing how to prepare the dish. Held by a
<code>textarea</code> element
</dd>
</dl>
<p>We’ll need a submit button to save a new or edited recipe.</p>
</div>
<div id="part-1.3-what-are-our-web-pages" class="slide section level1">
<h1>Part 1.3: What are our web pages?</h1>
<dl>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/htdocs1/index.html"
title="you may retrieve the contents via curl or irm">htdocs/index.html</a></dt>
<dd>
Display a list of our recipes
</dd>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main//htdocs1/display_recipe.html"
title="you may retrieve the contents via curl or irm">htdocs/display_recipe.html</a></dt>
<dd>
A page that shows the recipe
</dd>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main//htdocs1/edit_recipe.html"
title="you may retrieve the contents via curl or irm">htdocs/edit_recipe.html</a></dt>
<dd>
A page used to add and edit recipes we’ve collected
</dd>
</dl>
</div>
<div id="part-1.3-populating-our-pages-using-javascript"
class="slide section level1">
<h1>Part 1.3: Populating our pages using JavaScript</h1>
<p>We’ll create four modules, one specific to each HTML page and one
utility module</p>
<dl>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/htdocs1/modules/index_recipes.js"
title="you may retrieve the contents via curl or irm">htdocs/modules/index_recipes.js</a></dt>
<dd>
Display a list of our recipes
</dd>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main//htdocs1/modules/display_recipe.js"
title="you may retrieve the contents via curl or irm">htdocs/modules/display_recipe.js</a></dt>
<dd>
A page that shows the recipe
</dd>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main//htdocs1/modules/edit_recipe.js"
title="you may retrieve the contents via curl or irm">htdocs/modules/edit_recipe.js</a></dt>
<dd>
A page used to add and edit recipes we’ve collected
</dd>
<dt><a
href="https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/htdocs1/modules/utils.js"
title="you may retrieve the contents via curl or irm">htdocs/modules/utils.js</a></dt>
<dd>
This module handles retrieving data from the JSON API and finding the
object’s key
</dd>
</dl>
</div>
<div id="part-1.3-fire-up-our-web-service" class="slide section level1">
<h1>Part 1.3: Fire up our web service</h1>
<p>In a terminal run our startup command</p>
<pre class="shell"><code>datasetd -debug recipes_api.yaml</code></pre>
</div>
<div id="part-1.3-test-using-your-web-browser"
class="slide section level1">
<h1>Part 1.3: Test using your web browser</h1>
<ol style="list-style-type: decimal">
<li>Go to <a href="http://localhost:8001"
class="uri">http://localhost:8001</a></li>
<li>In your browser turn on your developer tools</li>
<li>Reload the page</li>
<li>Explore while your developer tools are turned on</li>
</ol>
</div>
<div id="part-1.3-debugging-and-improving" class="slide section level1">
<h1>Part 1.3: Debugging and improving</h1>
<ol style="list-style-type: decimal">
<li>Are there issues to debug?</li>
<li>What happens when you add a recipe?</li>
<li>What happens when you when you update a receipt?</li>
<li>Can any of this be improved?</li>
</ol>
</div>
<div id="part-1.3-what-weve-learned-in-part-1"
class="slide section level1">
<h1>Part 1.3: What we’ve learned in Part 1</h1>
<blockquote>
<p>Thank you for participating</p>
</blockquote>
<ul>
<li>The back end can be “turn key” only requiring a simple YAML
file</li>
<li>Basic HTML is enough to prototype a minimal web application
<ul>
<li>A little JavaScript, browser side turns an API into a working
prototype</li>
</ul></li>
<li>Our prototype is only a starting point</li>
</ul>
<p>Improve the user experience with in Part 2 of the workshop, <a
href="presentation2.html">Dataset & Web Components</a></p>
</div>
<div id="reference-dataset" class="slide section level1">
<h1>Reference: Dataset</h1>
<ul>
<li><a href="https://caltechlibrary.github.io/dataset">Dataset
Project</a></li>
<li><a href="https://github.com/caltechlibrary/dataset">Dataset
Repository</a></li>
<li><a href="https://github.com/caltechlibrary/dataset/issues">Getting
help with Dataset</a></li>
</ul>
</div>
<div id="reference-programming-languages" class="slide section level1">
<h1>Reference: Programming Languages</h1>
<ul>
<li><a
href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content">HTML5</a>,
structured content</li>
<li><a
href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics">CSS</a>,
layout and style</li>
<li><a
href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting">JavaScript</a>,
behaviors and web components</li>
<li><a href="https://sqlite.org">SQL and SQLite</a>
<ul>
<li><a href="https://www.sqlitetutorial.net/">SQLite Tutorial</a></li>
<li>Or typing into your favorite LLM, but be prepared to validate the
recommendations</li>
</ul></li>
<li><a href="https://developer.mozilla.org/en-US">MDN</a></li>
</ul>
</div>
<div id="reference-data-formats" class="slide section level1">
<h1>Reference: Data formats</h1>
<ul>
<li><a href="https://www.json.org">JSON</a></li>
<li><a href="https://jsonlines.org">JSON Lines</a></li>
<li><a href="https://yaml.org/">YAML</a></li>
</ul>
</div>
<div id="thank-you-for-participating" class="slide section level1">
<h1>Thank you for participating</h1>
<ul>
<li>View presentations:
<ul>
<li><a
href="https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html"
class="uri">https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html</a></li>
<li><a
href="https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation2.html"
class="uri">https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation2.html</a></li>
<li><a
href="https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation3.html"
class="uri">https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation3.html</a></li>
</ul></li>
<li>View the repository: <a
href="https://github.com/caltechlibrary/t2t3_dataset_web_apps"
class="uri">https://github.com/caltechlibrary/t2t3_dataset_web_apps</a></li>
<li>Comment on this presentation: <a
href="https://github.com/caltechlibrary/t2t3_dataset_web_apps/issues"
class="uri">https://github.com/caltechlibrary/t2t3_dataset_web_apps/issues</a></li>
<li>Author: R. S. Doiel, <a href="mailto:[email protected]"
class="uri">mailto:[email protected]</a></li>
</ul>
</div>
</body>
</html>