<?xml version="1.0" encoding="UTF-8" standalone="yes"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us"><id>https://blog.pgxn.org/tags/rest/</id><title>REST</title><updated>2011-04-29T20:44:02Z</updated><link rel="self" type="application/atom+xml" href="https://blog.pgxn.org/tags/rest/feed.xml"/><link rel="alternate" type="text/html" href="https://blog.pgxn.org/tags/rest/"/><author><name>The PGXN Maintainers</name></author><generator uri="https://gohugo.io/" version="0.167.0">Hugo</generator><entry><id>https://blog.pgxn.org/post/5049235040</id><title type="html">About the Infrastructure: PGXN API</title><link rel="alternate" type="text/html" href="https://blog.pgxn.org/2011/about-pgxn-api/"/><updated>2026-10-07T16:13:48Z</updated><published>2011-04-29T20:44:02Z</published><author><name>David E. Wheeler</name></author><category scheme="https://blog.pgxn.org/tags" term="infrastructure" label="Infrastructure"/><category scheme="https://blog.pgxn.org/tags" term="api" label="API"/><category scheme="https://blog.pgxn.org/tags" term="api-server" label="API Server"/><category scheme="https://blog.pgxn.org/tags" term="metadata" label="Metadata"/><category scheme="https://blog.pgxn.org/tags" term="rest" label="REST"/><category scheme="https://blog.pgxn.org/tags" term="http" label="Http"/><summary type="html"><![CDATA[<p>The second piece of the PGXN infrastructure, after <a href="https://blog.pgxn.org/post/4854707157/pgxn-manager" title="About the Infrastructure: PGXN Manager">PGXN Maanager</a>, is the
<a href="https://api.pgxn.org/">PGXN API Server</a>. I&rsquo;ve just finished the <a href="https://github.com/pgxn/pgxn-api/wiki">API documentation</a>, which covers
both the lightweight static file API provided by mirrors and the superset
provided by the API server. So now seems like a good time to talk about the
design of the API server and how it works.</p>
<p>At its core, the PGXN API server is just another mirror. It has an hourly cron
job that <code>rsync</code>s to the master mirror, updating the mirror. But then it
iterates over the <code>rsync</code> log and transforms some things. Here&rsquo;s what it does:</p>]]></summary><content type="html" xml:base="https://blog.pgxn.org/" xml:space="preserve"><![CDATA[<p>The second piece of the PGXN infrastructure, after <a href="https://blog.pgxn.org/post/4854707157/pgxn-manager" title="About the Infrastructure: PGXN Manager">PGXN Maanager</a>, is the
<a href="https://api.pgxn.org/">PGXN API Server</a>. I&rsquo;ve just finished the <a href="https://github.com/pgxn/pgxn-api/wiki">API documentation</a>, which covers
both the lightweight static file API provided by mirrors and the superset
provided by the API server. So now seems like a good time to talk about the
design of the API server and how it works.</p>
<p>At its core, the PGXN API server is just another mirror. It has an hourly cron
job that <code>rsync</code>s to the master mirror, updating the mirror. But then it
iterates over the <code>rsync</code> log and transforms some things. Here&rsquo;s what it does:</p>
<ul>
<li>Unpacks each distribution in a directory for browsing. Here, for example, is
where one can <a href="https://api.pgxn.org/src/semver/semver-0.2.1/">browse the semver 0.2.1</a> sources.</li>
<li>Searches for a <code>README</code> file and any files recognized by <a href="https://search.cpan.org/perldoc?Text::Markup">Text::Markup</a> and
converts them to sanitized HTML with a table of contents. Such files can
then be used to display the <code>README</code> on the <a href="https://pgxn.org/dist/semver/" title="semver distribution page">distribution page</a> and to
display <a href="https://pgxn.org/dist/semver/doc/semver.html" title="semver documentation">individual documentation files</a>.</li>
<li>Merges the distribution metadata file with the latest stable release
<code>META.json</code> generated by PGXN Manager. For example, as of this writing, the
API server&rsquo;s <a href="https://api.pgxn.org/dist/semver/0.2.1/META.json">semver 0.2.1 <code>META.json</code></a> and the unversioned <a href="https://api.pgxn.org/dist/semver.json">semver.json</a>
are identical. Effectively, this format has all the metadata from the
<code>META.json</code> as well as a list of all releases of the distribution from the
<code>semver.json</code>. This is useful for displaying all the data on the
<a href="https://pgxn.org/dist/semver/" title="semver distribution page">distribution page</a> by fetching the data in a single API request.</li>
<li>Updates all other versions of the <code>META.json</code> file. For example, if you look
at the <a href="https://api.pgxn.org/dist/semver/0.2.0/META.json">semver 0.0.0 <code>META.json</code></a>, you&rsquo;ll see that it includes 0.2.1 in its
list of releases, even though 0.2.1 was released after 0.2.0. This allows
<a href="https://pgxn.org/dist/semver/0.2.0/">semver 0.2.0</a> page on the main site to have a select list of version to
choose from, including versions released later, with a single API request.</li>
<li>Adds additional metadata to the extension JSON file for all extensions in
the distribution. The added data includes release dates for the list all
distributions providing the extension, as well as an abstract and doc path
for the latest stable release. To see the differences, compare the <a href="https://api.pgxn.org/mirror/extension/semver.json">mirror
<code>semver.json</code></a> to the <a href="https://api.pgxn.org/extension/semver.json">API <code>semver.json</code></a>.</li>
<li>Adds an abstract for each distribution listed in the user&rsquo;s JSON file and
all tag JSON files. Compare, for example, the <a href="https://api.pgxn.org/mirror/user/theory.json">mirror <code>theory.json</code></a> to the
<a href="https://api.pgxn.org/user/theory.json">API <code>theory.json</code></a> and the <a href="https://api.pgxn.org/mirror/tag/data%20types.json">mirror <code>data types.json</code></a> to the <a href="https://api.pgxn.org/tag/data%20types.json">API
<code>data types.json</code></a>. This allows the <a href="https://pgxn.org/user/theory">user page</a> and <a href="https://pgxn.org/tag/data%20types/">tag pages</a> to include
the abstract in the list of distributions released by the user or associated
with a tag.</li>
<li>Adds records to a <a href="https://incubator.apache.org/lucy/">Lucy</a>-powered full text search index.</li>
</ul>
<p>All of this merging stuff came out of my thinking following the discussion of
the <a href="https://blog.pgxn.org/post/3099288750/pgxn-api-rfc">PGXN API RFC</a>. The decision to use <a href="https://incubator.apache.org/lucy/">Lucy</a> instead of PostgreSQL&rsquo;s
<a href="https://www.postgresql.org/docs/current/static/textsearch.html">full-text search</a> followed rather naturally from this, as I quickly realized
that there was no other driving need for a relational database behind the API
at all. The <em>only</em> dynamic API is the <a href="https://github.com/pgxn/pgxn-api/wiki/search-api">search API</a>. Everything else is just
static files. And given the <a href="https://www.depesz.com/index.php/2010/10/17/why-im-not-fan-of-tsearch-2/">performance issues</a> of in-database search, as
well as the desire to have fewer outside dependencies, made the decision a
natural one.</p>
<p>Beyond the syncing, there is a very simple web server providing the HTTP REST
interface to the static JSON files and the full-text search. That&rsquo;s it,
really. The API server is really just another mirror on steroids. The nice
thing is that it allows an interface, such as <a href="https://search.cpan.org/perldoc?WWW::PGXN">WWW::PGXN</a> or the new <a href="https://blog.pgxn.org/post/5026314153/writing-a-client-for-pgxn">PGXN
client</a> to work with either interface, just failing gracefully when API server
APIs are unavailable.</p>
<p>If you want to learn more about the specifics of the REST API, the <a href="https://github.com/pgxn/pgxn-api/wiki">API
documentation</a> has <em>all</em> the details. Really, it&rsquo;s quite comprehensive!</p>
<p>I actually consider the API to be 1.0-complete at this point, unlike PGXN
Manager. The only thing I want to add is <a href="https://en.wikipedia.org/wiki/JSONP">JSONP</a> support for static JSON files
(right now it&rsquo;s only for search results) and might tweak a few things here and
there, but otherwise I think it&rsquo;s in pretty good shape.</p>
<p>Longer term, though, it might be worthwhile to add some other features to
enhance the value of PGXN overall. Some ideas:</p>
<ul>
<li>Distribution and/or extension ratings (reviews, Like/Dislike, stars, or
something).</li>
<li>Diffs to compare changes between versions.</li>
<li>A test reporting infrastructure with result matrices (á la <a href="https://www.cpantesters.org/">CPAN Testers</a>.</li>
</ul>
<p>But I think we need to build up some momentum on the foundation that&rsquo;s in
place. Have you submitted your extensions, yet?</p>
]]></content></entry><entry><id>https://blog.pgxn.org/post/988613682</id><title type="html">A RESTful Directory</title><link rel="alternate" type="text/html" href="https://blog.pgxn.org/2010/restful-directory/"/><updated>2026-10-07T16:13:48Z</updated><published>2010-08-21T18:52:00Z</published><author><name>David E. Wheeler</name></author><category scheme="https://blog.pgxn.org/tags" term="mirror" label="Mirror"/><category scheme="https://blog.pgxn.org/tags" term="directory" label="Directory"/><category scheme="https://blog.pgxn.org/tags" term="structure" label="Structure"/><category scheme="https://blog.pgxn.org/tags" term="meta" label="Meta"/><category scheme="https://blog.pgxn.org/tags" term="metadata" label="Metadata"/><category scheme="https://blog.pgxn.org/tags" term="json" label="JSON"/><category scheme="https://blog.pgxn.org/tags" term="api" label="API"/><category scheme="https://blog.pgxn.org/tags" term="scalability" label="Scalability"/><category scheme="https://blog.pgxn.org/tags" term="rest" label="REST"/><summary type="html"><![CDATA[Following my post outlining a possible network <a href="https://blog.pgxn.org/post/954535657/thoughts-on-the-network-directory-structure">directory structure</a>,
<a href="https://plasmasturm.org/">Aristotle Pagaltzis</a> saw fit to bug me via email about a different approach.
I couldn&rsquo;t understand WTF he was talking about until today. Then it lit my
brain on fire. As a result, I now think that there is a much better way to
organize the metadata files for the PGXN &ndash; one that happens not to include
any symbolic links (which is something that <a href="https://search.cpan.org/~andk/">Andreas König</a> has been flagging,
via email, as a possible bottleneck).]]></summary><content type="html" xml:base="https://blog.pgxn.org/" xml:space="preserve"><![CDATA[<p>Following my post outlining a possible network <a href="https://blog.pgxn.org/post/954535657/thoughts-on-the-network-directory-structure">directory structure</a>,
<a href="https://plasmasturm.org/">Aristotle Pagaltzis</a> saw fit to bug me via email about a different approach.
I couldn&rsquo;t understand WTF he was talking about until today. Then it lit my
brain on fire. As a result, I now think that there is a much better way to
organize the metadata files for the PGXN &ndash; one that happens not to include
any symbolic links (which is something that <a href="https://search.cpan.org/~andk/">Andreas König</a> has been flagging,
via email, as a possible bottleneck).</p>
<p>First, the <code>/dist</code> directory will be the same as before. Releases of pgTAP
would be in:</p>
<pre tabindex="0"><code>dist/p/pg/pgtap/pgtap-0.23.pgz
dist/p/pg/pgtap/pgtap-0.23.json
dist/p/pg/pgtap/pgtap-0.23.readme
dist/p/pg/pgtap/pgtap-0.24.pgz
dist/p/pg/pgtap/pgtap-0.24.json
dist/p/pg/pgtap/pgtap-0.24.readme
dist/p/pg/pgtap/pgtap-0.25.pgz
dist/p/pg/pgtap/pgtap-0.25.json
dist/p/pg/pgtap/pgtap-0.25.readme
</code></pre><p>The only change is that the <code>pgtap.json</code> symlink is gone.</p>
<p>Now, the new stuff. In the root directory will be a file, <code>index.json</code>, that
contains templates for URIs. It will look something like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;dist&#34;</span><span class="p">:</span>   <span class="s2">&#34;/dist/$a/$ab/$dist/$dist-$version.pgz&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;readme&#34;</span><span class="p">:</span> <span class="s2">&#34;/dist/$a/$ab/$dist/$dist-$version.readme&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;meta&#34;</span><span class="p">:</span>   <span class="s2">&#34;/dist/$a/$ab/$dist/$dist-$version.json&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;by-dist&#34;</span><span class="p">:</span>      <span class="s2">&#34;/by/dist/$a/$ab/$dist.json&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;by-extension&#34;</span><span class="p">:</span> <span class="s2">&#34;/by/extension/$a/$ab/$extension.json&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;by-owner&#34;</span><span class="p">:</span>     <span class="s2">&#34;/by/owner/$a/$ab/$owner.json&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;by-manager&#34;</span><span class="p">:</span>   <span class="s2">&#34;/by/manager/$a/$ab/$manager.json&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>The PGXN client will always fetch this file before it does anything else,
because the file tells it how to find stuff. The advantage here is that the
client doesn&rsquo;t have to know anything about how the directory is actually
organized, just what the template variables might be. They are:</p>
<ul>
<li><code>$dist</code>: A <a href="https://github.com/theory/pgxn/wiki/PGXN-Meta-Spec#name">distribution name</a></li>
<li><code>$version</code>: A <a href="https://github.com/theory/pgxn/wiki/PGXN-Meta-Spec#version">version number</a></li>
<li><code>$extension</code>: An <a href="https://github.com/theory/pgxn/wiki/PGXN-Meta-Spec#provides">extension name</a></li>
<li><code>$owner</code>: An <a href="https://github.com/theory/pgxn/wiki/PGXN-Meta-Spec#owner">owner&rsquo;s name</a></li>
<li><code>$manager</code>: A release manager&rsquo;s name (managers are the people who upload
distributions to PGXN)</li>
<li><code>$a</code>: The first letter of a distribution, extension, owner, or manager name.</li>
<li><code>$ab</code>: The first two letters of a distribution, extension, owner, or manager
name.</li>
</ul>
<p>I&rsquo;m not thrilled about using prefix-staggering to avoid having too many files
in a directory. But the truth is that this approach allows me to punt. I could
also make sure the client supports, for example, <code>$bc</code> and <code>$cd</code>, so that one
could stagger things differently. And then the nice thing is that I don&rsquo;t have
to use those at all. The templates will tell the client exactly how to
construct the URIs for things, and the templates needn&rsquo;t include those
staggering variables if they&rsquo;re not appropriate. The client won&rsquo;t care because
it will have no built-in knowledge of how things are organized. It will have
to find out from <code>index.json</code>.</p>
<p>From the URI templates, you can now see where the other metadata will be
stored. For extension names, a hypothetical pgTAP distribution with two
extensions will have a JSON file for each extension:</p>
<pre tabindex="0"><code>/by/extension/p/pg/pgtap.json
/by/extension/s/sc/schematap.json
</code></pre><p>The <code>pgtap.json</code> file will look something like this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="s2">&#34;stable&#34;</span><span class="err">:</span>   <span class="s2">&#34;0.25.0&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;testing&#34;</span><span class="err">:</span>  <span class="s2">&#34;0.26.0b1&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;unstable&#34;</span><span class="err">:</span> <span class="s2">&#34;0.30.0u&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;versions&#34;</span><span class="err">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.26.0b1&#34;</span><span class="p">:</span> <span class="p">{</span> <span class="nt">&#34;dist&#34;</span><span class="p">:</span> <span class="s2">&#34;pgtap&#34;</span><span class="p">,</span> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.26.0b1&#34;</span><span class="p">,</span> <span class="nt">&#34;status&#34;</span><span class="p">:</span> <span class="s2">&#34;testing&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.30.0u&#34;</span><span class="p">:</span>  <span class="p">{</span> <span class="nt">&#34;dist&#34;</span><span class="p">:</span> <span class="s2">&#34;pgtap&#34;</span><span class="p">,</span> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.30.0u&#34;</span><span class="p">,</span>  <span class="nt">&#34;status&#34;</span><span class="p">:</span> <span class="s2">&#34;unstable&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.25.0&#34;</span><span class="p">:</span>   <span class="p">{</span> <span class="nt">&#34;dist&#34;</span><span class="p">:</span> <span class="s2">&#34;pgtap&#34;</span><span class="p">,</span> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.25.0&#34;</span><span class="p">,</span>   <span class="nt">&#34;status&#34;</span><span class="p">:</span> <span class="s2">&#34;stable&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.24.0&#34;</span><span class="p">:</span>   <span class="p">{</span> <span class="nt">&#34;dist&#34;</span><span class="p">:</span> <span class="s2">&#34;pgtap&#34;</span><span class="p">,</span> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.24.0&#34;</span><span class="p">,</span>   <span class="nt">&#34;status&#34;</span><span class="p">:</span> <span class="s2">&#34;stable&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.25.0&#34;</span><span class="p">:</span>   <span class="p">{</span> <span class="nt">&#34;dist&#34;</span><span class="p">:</span> <span class="s2">&#34;pgtap&#34;</span><span class="p">,</span> <span class="nt">&#34;version&#34;</span><span class="p">:</span> <span class="s2">&#34;0.23.0&#34;</span><span class="p">,</span>   <span class="nt">&#34;status&#34;</span><span class="p">:</span> <span class="s2">&#34;stable&#34;</span>  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>Right at the top, it would always list the most recent stable, testing, and
unstable version number, and then it would have a list metadata for all
versions. Said metadata would include the associated distribution name,
version, and release status.</p>
<p>Here&rsquo;s how it would work. Say I ask the client to install pgtap:</p>
<pre tabindex="0"><code>PGXN&gt; install extension pgtap
</code></pre><p>The client would first fetch <code>/index.json</code>, then look for the URI template for
&ldquo;by-extension&rdquo;, which is <code>/by/extension/$a/$ab/$extension.json</code>. Filling in
the template, it would know to request <code>/by/extension/p/pg/pgtap.json</code>. With
that file, it would see that the most recent stable version is in the &ldquo;pgtap&rdquo;
distribution version 0.25.0. Using the <code>dist</code> URI template, which is
<code>/dist/$a/$ab/$dist-$version.pgz</code>, it would then fetch
<code>/dist/p/pg/pgtap/pgtap-0.25.0.pgz</code>.</p>
<p>The advantage here is that there are no symbolic links and no knowledge of the
directory structure built into clients. The client just knows to fetch
<code>/index.json</code> and then to use the templates in that file to fetch other
information. That&rsquo;s the whole interface. Very <a href="https://en.wikipedia.org/wiki/REST">REST</a>ful.</p>
<p>The structure of the other <code>/by</code> files would be similar. For</p>
<pre><code>PGXN&gt; install dist pgtap
</code></pre>
<p>the client would use the &ldquo;by-dist&rdquo; URI template to construct the URL
<code>/by/dist/p/pg/pgtap.json</code>. That file would have something like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="s2">&#34;stable&#34;</span><span class="err">:</span>   <span class="s2">&#34;0.25.0&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;testing&#34;</span><span class="err">:</span>  <span class="s2">&#34;0.26.0b1&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;unstable&#34;</span><span class="err">:</span> <span class="s2">&#34;0.30.0u&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;versions&#34;</span><span class="err">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.26.0b1&#34;</span><span class="p">:</span> <span class="s2">&#34;testing&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.30.0u&#34;</span><span class="p">:</span>  <span class="s2">&#34;unstable&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.25.0&#34;</span><span class="p">:</span>   <span class="s2">&#34;stable&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.24.0&#34;</span><span class="p">:</span>   <span class="s2">&#34;stable&#34;</span> <span class="p">,</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;0.23.0&#34;</span><span class="p">:</span>   <span class="s2">&#34;stable&#34;</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>So then the client would know that &ldquo;0.25.0&rdquo; was the most recent version, and
use the <code>dist</code> URI template to request <code>/dist/p/pg/pgtap/pgtap-0.25.0.pgz</code>.</p>
<p>If The client command had been:</p>
<pre tabindex="0"><code>PGXN&gt; readme dist pgtap
</code></pre><p>It would use the <code>readme</code> URI template. And the command:</p>
<pre tabindex="0"><code>PGXN&gt; meta dist pgtap
</code></pre><p>Would use the <code>meta</code> URI template to fetch the metadata for the distribution.</p>
<p>If the client had requested a specific version:</p>
<pre tabindex="0"><code>PGXN&gt; install dist 0.23.0
</code></pre><p>It could either use the <code>by-dist</code> URI template to download the list of all
versions to see if 0.23.0 was valid, or just use the <code>dist</code> URI template to
try to download the distribution itself.</p>
<p>And finally, the owner and manager JSON files, such as</p>
<pre tabindex="0"><code>/owner/t/th/theory.json
</code></pre><p>Would look something like:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="s2">&#34;full_name&#34;</span><span class="err">:</span> <span class="s2">&#34;David Wheeler&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;email&#34;</span><span class="err">:</span> <span class="s2">&#34;theory@pgxn.org&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;uri&#34;</span><span class="err">:</span> <span class="s2">&#34;https://justatheory.com&#34;</span><span class="err">,</span>
</span></span><span class="line"><span class="cl"><span class="s2">&#34;distributions&#34;</span><span class="err">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;pgtap&#34;</span><span class="p">:</span> <span class="p">[</span> <span class="s2">&#34;0.25.0&#34;</span><span class="p">,</span> <span class="s2">&#34;0.24.0&#34;</span><span class="p">,</span> <span class="s2">&#34;0.23.0&#34;</span> <span class="p">]</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;pair&#34;</span><span class="p">:</span> <span class="p">[</span> <span class="s2">&#34;0.2.0&#34;</span><span class="p">,</span> <span class="s2">&#34;0.1.0&#34;</span><span class="p">,</span> <span class="s2">&#34;0.0.5&#34;</span> <span class="p">]</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>With that, the client can be asked to fetch metadata for a given owner name
and use it to figure out what distributions and versions the the owner, um,
owns. One could then fetch the metadata, readme, or distribution file for any
of those distributions and versions.</p>
<p>Overall, I think that this is a much better solution than I outlined
<a href="https://blog.pgxn.org/post/954535657/thoughts-on-the-network-directory-structure">before</a>. If only I could figure out something more
elegant that the prefix-staggering/hashing stuff, it would be just about
perfect.</p>
<p>Thoughts?</p>
]]></content></entry><entry><id>https://blog.pgxn.org/post/954535657</id><title type="html">Thoughts on the Network Directory Structure</title><link rel="alternate" type="text/html" href="https://blog.pgxn.org/2010/thoughts-on-the-network-directory-structure/"/><updated>2026-10-07T16:13:48Z</updated><published>2010-08-14T23:59:12Z</published><author><name>David E. Wheeler</name></author><category scheme="https://blog.pgxn.org/tags" term="mirror" label="Mirror"/><category scheme="https://blog.pgxn.org/tags" term="directory" label="Directory"/><category scheme="https://blog.pgxn.org/tags" term="structure" label="Structure"/><category scheme="https://blog.pgxn.org/tags" term="metadata" label="Metadata"/><category scheme="https://blog.pgxn.org/tags" term="json" label="JSON"/><category scheme="https://blog.pgxn.org/tags" term="api" label="API"/><category scheme="https://blog.pgxn.org/tags" term="scalability" label="Scalability"/><category scheme="https://blog.pgxn.org/tags" term="rest" label="REST"/><summary type="html"><![CDATA[<p>I&rsquo;ve been thinking about the arrangement of stuff to be distributed to the
mirrors. In doing so, I&rsquo;ve kept three goals in mind:</p>
<ol>
<li>Allow things to scale.</li>
<li>Try to put things in intuitive locations.</li>
<li>Allow for metadata to be stored to act as a Web API.</li>
</ol>
<p>The first two are a bit mutually-contradicting. Thinking scalability mainly
means minimizing the chances that too many files can be put into a single
directory. <a href="https://www.cpan.org/misc/ZCAN.html" title="Zen of Comprehensive Archive Networks (look for “Naming”)">CPAN</a> started out with all author directories in a single
directory. Given the sheer number of CPAN contributors, this quickly got to be
a bottleneck. To correct for that, they started &ldquo;hashing&rdquo; the first two
letters of author names to create subdirectories. My CPAN directory, for
example, is <a href="https://www.cpan.org/authors/id/D/DW/DWHEELER/"><code>D/DW/DWHEELER</code></a>. That doesn&rsquo;t quite make for an intuitive
location, but it&rsquo;s not bad, and the tradeoff seems sufficient to keep things
sane.</p>]]></summary><content type="html" xml:base="https://blog.pgxn.org/" xml:space="preserve"><![CDATA[<p>I&rsquo;ve been thinking about the arrangement of stuff to be distributed to the
mirrors. In doing so, I&rsquo;ve kept three goals in mind:</p>
<ol>
<li>Allow things to scale.</li>
<li>Try to put things in intuitive locations.</li>
<li>Allow for metadata to be stored to act as a Web API.</li>
</ol>
<p>The first two are a bit mutually-contradicting. Thinking scalability mainly
means minimizing the chances that too many files can be put into a single
directory. <a href="https://www.cpan.org/misc/ZCAN.html" title="Zen of Comprehensive Archive Networks (look for “Naming”)">CPAN</a> started out with all author directories in a single
directory. Given the sheer number of CPAN contributors, this quickly got to be
a bottleneck. To correct for that, they started &ldquo;hashing&rdquo; the first two
letters of author names to create subdirectories. My CPAN directory, for
example, is <a href="https://www.cpan.org/authors/id/D/DW/DWHEELER/"><code>D/DW/DWHEELER</code></a>. That doesn&rsquo;t quite make for an intuitive
location, but it&rsquo;s not bad, and the tradeoff seems sufficient to keep things
sane.</p>
<p>The storage of metadata is important, too, as I plan to have the <a href="https://pgxn.org/status.html#client">client</a> send
requests for JSON files to mirrors in order to find distributions. Basically,
this came down to a naming convention, as well as a recipe for how to find
metadata files for people and extensions. What I&rsquo;ve come up with is three
directories:</p>
<ul>
<li><code>meta</code> will contain PGXN metadata</li>
<li><code>dist</code> will contain distributions</li>
<li><code>by</code> will contain query-able JSON files</li>
</ul>
<p>The <code>meta</code> directory will contain PGXN metadata (<code>mirrors.json</code>, timestamp,
other detritus). If I ever create an index file that lists all distributions,
it would go there, too. I&rsquo;m not going to discuss it any further here, except
to note that it already has <code>mirrors.json</code>, which clients will be able to use
to present users with a list of mirrors to choose from.</p>
<p>The <code>dist</code> directory will be organized with directories named with &ldquo;hashes&rdquo; of
the first two letters of distribution names. Let&rsquo;s say that I&rsquo;m releasing
<a href="https://pgtan.org/">pgTAP</a> 0.25 on PGXN. To distribute it, the management application will create
the directory (if it doesn&rsquo;t already exist):</p>
<pre tabindex="0"><code>dist/p/pg/pgtap/
</code></pre><p>Then, for the 0.25 release, it will add three files to that directory:</p>
<pre tabindex="0"><code>dist/p/pg/pgtap/pgtap-0.25.pgz
dist/p/pg/pgtap/pgtap-0.25.json
dist/p/pg/pgtap/pgtap-0.25.readme
</code></pre><p>The <code>pgtap-0.25.pgz</code> file will contain the <a href="https://wiki.postgresql.org/wiki/PGXN#Distribution_Layout">zipped distribution</a> ready for
download. <code>pgtap-0.25.json</code> will contain metadata about the distribution, such
as the owner&rsquo;s name, the manager&rsquo;s name (more on these folks below), list of
included extensions, location of the <code>.pgz</code> and <code>.readme</code>, and its SHA1.
<code>pgtap-0.25.readme</code> will of course contain the <code>README</code> for the distribution
(if it has one).</p>
<p>Every release of pgTAP will have these three files, so after several releases,
the <code>pgtap</code> directory might have these files:</p>
<pre tabindex="0"><code>dist/p/pg/pgtap/pgtap-0.23.pgz
dist/p/pg/pgtap/pgtap-0.23.json
dist/p/pg/pgtap/pgtap-0.23.readme
dist/p/pg/pgtap/pgtap-0.24.pgz
dist/p/pg/pgtap/pgtap-0.24.json
dist/p/pg/pgtap/pgtap-0.24.readme
dist/p/pg/pgtap/pgtap-0.25.pgz
dist/p/pg/pgtap/pgtap-0.25.json
dist/p/pg/pgtap/pgtap-0.25.readme
dist/p/pg/pgtap/pgtap.json
</code></pre><p>The last file there, <code>pgtap.json</code>, will actually be a symlink to the JSON file
for latest production release of pgTAP. In this case, it would link to
<code>pgtap-0.25.json</code>. The nice thing about this is that, if a client wants to
find the information about the latest release of the pgtap distribution, all
it will have to do is send an HTTP GET request for
<code>dist/p/pg/pgtap/pgtap.json</code> to any mirror.</p>
<p>The <code>by</code> directory will also contain JSON files for clients to request. The
idea is that you want to find information &ldquo;by&rdquo; something. To start with, there
will be three subdirectories:</p>
<pre tabindex="0"><code>by/extension/
by/manager/
by/owner/
</code></pre><p>The first directory, <code>by/extension/</code>, will contain links to JSON files for
extensions. Say that the pgTAP distribution offers two extensions to
PostgreSQL named &ldquo;pgtap&rdquo; and &ldquo;schematap&rdquo;. The links would be:</p>
<pre tabindex="0"><code>by/extension/p/pg/pgtap/pgtap-0.23.json
by/extension/p/pg/pgtap/pgtap-0.24.json
by/extension/p/pg/pgtap/pgtap-0.25.json
by/extension/p/pg/pgtap/pgtap.json
</code></pre><p>Each of these will simply be symlinks pointing to the appropriate distribution
files:</p>
<pre tabindex="0"><code>dist/p/pg/pgtap/pgtap-0.23.json
dist/p/pg/pgtap/pgtap-0.24.json
dist/p/pg/pgtap/pgtap-0.25.json
dist/p/pg/pgtap/pgtap.json
</code></pre><p>Yes, the last one is a symlink to a symlink. Similarly, these files for
&ldquo;schematap&rdquo;:</p>
<pre tabindex="0"><code>by/extension/s/sc/schematap/schematap-0.23.json
by/extension/s/sc/schematap/schematap-0.24.json
by/extension/s/sc/schematap/schematap-0.25.json
by/extension/s/sc/schematap/schematap.json
</code></pre><p>Point to exactly the same files. Essentially, this is a way for extensions to
point to the distributions that contain them.
<code>by/extension/s/sc/schematap/schematap.json</code> points to
<code>dist/p/pg/pgtap/pgtap.json</code>, which contains path to the <code>.pgz</code> file to
download (and lots of other metadata, too).</p>
<p>The idea is that, whatever the name of the extension you want, the client will
be able to easily find the metadata file that tells it where to find the
distribution.</p>
<p>The <code>by/manager</code> and <code>by/owner</code> directories, on the other hand, contain JSON
files with information about managers and owners and their distributions.
Definitions:</p>
<p>An &ldquo;owner&rdquo; is someone who <em>owns</em> a distribution. This will often be the
original author of an extension, but may be someone else if maintenance has
been passed on. Basically, the &ldquo;owner&rdquo; is the person who should be contacted
with bug reports and the like</p>
<p>A &ldquo;manager&rdquo; is someone who manages the release process. This is the user who
will log into the PGXN management application and upload a distribution for
release.</p>
<p>These two people will often be the same person, but not always. I&rsquo;ve avoided
the term &ldquo;author&rdquo; (the term used by CPAN) because the author of an extension
may no longer maintain it. &ldquo;Owner&rdquo; seemed like a better choice (individual
distributions are free to describe their contributors however they wish).</p>
<p>As the <em>owner</em> of a few extensions on PGXN, I&rsquo;d have this file:</p>
<pre tabindex="0"><code>by/owner/t/th/theory.json
</code></pre><p>This file would contain a list of my distributions and perhaps some other
information (like my full name and blog URL).</p>
<p>As the <em>manager</em> of extensions on PGXN (that is, I actually uploaded them), I
would also have:</p>
<pre tabindex="0"><code>by/manager/t/th/theory.json
</code></pre><p>This file would contain a list of the distributions I&rsquo;ve released on PGXN.
This might be exactly the same as the list in my owner file, but may not be.
Perhaps for one release of pgTAP, say 0.26, <a href="https://leto.net/dukeleto.pl/">Duke Leto</a> uploaded a release. In
that case, 0.26 would probably be in my owner file, but not in my manager
file: it would be in Duke&rsquo;s manager file, instead.</p>
<p>So these are the basics of the directory structure for the networked mirrors.
Note that I haven&rsquo;t thought much about everything that will go into the JSON
files (or whether or not they&rsquo;d be versioned). That will likely depend quite a
lot on what the management database ends up looking like. I&rsquo;ll be working on
that next.</p>
<p>But other than that, comments? Questions? Criticisms? Recommendations? Leave a
comment and let me know!</p>
]]></content></entry></feed>