, 9 tweets, 2 min read Read on Twitter
would anyone be interested in a brief explanation of the flow of API requests for a npm package install, or is this already general knowledge?
okay, I'll write this up in a larger form elsewhere, later, but: no time like the present and no... medium... like... the twitter feed, I suppose
here are the basic types in play:

a package has one metadata document, a JSON "packument"
a packument lists all of the versions of the package and the times they were published
a version has a tarball
there are two API endpoints:

- /${pkg urlencoded} for packuments
- /${pkg}/-/${name}-${version}.tgz for tarballs

e.g.:
- /lodash and /lodash/-/lodash-4.17.11.tgz, or
- /%40slack%2fclient and /﹫slack/client/-/client-4.8.0.tgz

(forgive the @-homoglyph there)
packuments contain {"versions": {[version]: Version}, "time": {[version]: Date}, "dist-tags": {"latest": [version], ...}}

if there's a version in "time" but not in "versions", it's been unpublished

"dist-tags" contains tag names, and is required to have "latest"
I'm handwaving the CLI magic that goes on (and it is really cool, check out zkat/pacote + cacache), BUT, generally the flow is:

GET /<pkg>
<figure out which version you wanted>
GET /<pkg>/-/<pkg>-<version>.tgz

(repeated for all <pkg>'s in the tree you want to install)
other stuff:

- send an accept header of "application/vnd.npm.install-v1+json" to get a shorter (or "corgi") packument (your CLI does this for you)
- to authorize a request, send "authorization: Bearer <your token>" (you can use basic auth too but please, please don't.)
- corgi packuments also advertise whether or not package-versions contain a shrinkwrap file, which saves CLIs a trip through untar
- each package-version contains a dist stanza with an SRI hash, unpacked size, file count, and npm signature
for public packages: you can get an ndjson list of the files+sizes inside the tarball! see:

GET /lodash/-/lodash-4.17.11.index (replacing "tgz" with "index")

(💞 to @soldair for this)
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Chris Dickinson
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!