R. S. Doiel, rsdoiel@caltech.edu
Caltech Library, Digital Library Development
2025-06-12
Welcome everyone. This is a hands on workshop (part 1).
An approach to building web applications using Dataset
Follow along at https://caltechlibrary.github.io/t2t3_dataset_web_apps/presentation1.html
Download the presentation zip file at https://github.com/caltechlibrary/t2t3_dataset_web_apps/releases
We can start our first iteration of our application once you have these available.
GOAL: A simple web application that lets us curate a list of recipes.
recipes.ds
collectionrecipes.ds
collectionWe use the dataset
command line program to initialize a
dataset collection.
dataset init recipes.ds
(Linux, macOS and Windows)
.jsonl
Download sample data file recipes.jsonl
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
On Windows:
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
dataset keys recipes.ds
dataset read recipes.ds frybread
$ dataset keys recipes.ds
blondies
brownies
cafe-con-leche
frybread
poi
waffles
$ 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"
}
mkdir htdocs
mkdir htdocs/css
mkdir htdocs/modules
datasetd
datasetd
web service is defined by a simple YAML file.
It has three top level attributes
NOTE: Dataset web service can host many collections at the same time.
YAML is a superset of JSON that is easy to read and easy to type.
host: localhost:8001
This line tells dataset web service that it should listen on port 8001 on localhost. Dataset web services always run on localhost.
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 htdocs
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.
The next element, collections
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,
recipes.ds
.
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.
If an permission is not included it is defaults to false. The value true will enabled it.
Here’s what the permissions look like for our web application.
SQL is a powerful language. Dataset only allows defined queries to be
run. One simple query is needed for our application,
index_recipes
.
host: localhost:8001
htdocs: htdocs
collections:
- dataset: recipes
keys: true
create: true
# Create redirectos do double duty as a POST also supports update.
create_success: http://localhost:8001/display_recipe.html
create_error: http://localhost:8001/edit_recipe.html
update: true
delete: false
query:
list_recipes: |
select src
from recipes
order by src->>'name'
YAML allows comments, here’s an example.
#!/usr/bin/env -S datasetd -debug
# Host and port to listen on
host: localhost:8001
# location of our static content
htdocs: htdocs
# Define the collections supported in our application
collections:
# Define the permissions and behavior of the API For our recipe collection
- dataset: recipes.ds
keys: true
create: true
# When we successfully create or update via a form using a POST method
# display the updated object
create_success: http://localhost:8001/display_recipe.html
# When we fail go back to the current page.
create_error: http://localhost:8001/edit_recipe.html
read: true
update: true
delete: false
query:
list_recipes: |
select src
from recipes
order by src->>'name'
On macOS and Linux you can cURL the recipes_api.yaml
using the following statement.
curl -o recipes_api.yaml \
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes_api1.yaml
On Windows
irm -OutFile recipes_api.yaml `
https://raw.githubusercontent.com/caltechlibrary/t2t3_dataset_web_apps/refs/heads/main/recipes_api1.yaml
Starting the web service.
datasetd -debug recipes_api.yaml
datasetd -debug recipes_api.yaml
”?(on macOS, Linux or Window’s WSL)
chmod 775 recipes_api.yaml
Now you can shorten start up to
./recipes_api.yaml
The web service is running but the htdocs directory is not populated.
What do you see when you go to http://localhost:8001/?
We can complete our application by building the front end with HTML, CSS and JavaScript.
input
element
textarea
or for display a
table
.
textarea
element
We’ll need a submit button to save a new or edited recipe.
We’ll create four modules, one specific to each HTML page and one utility module
In a terminal run our startup command
datasetd -debug recipes_api.yaml
Thank you for participating
Improve the user experience with in Part 2 of the workshop, Dataset & Web Components