npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@dasl/rasl

v1.2.1

Published

RASL implementation (Express, URL, Fetch)

Readme

@dasl/rasl — RASL implementation (Express, URL, Fetch)

RASL is a simple protocol to retrieve content-addressed data over HTTP. You can read more in the specification, which is part of the DASL project.

Installation

npm install @dasl/rasl

Express Handler

import rasl from '@dasl/rasl';
import express from 'express';

const app = express();

app.use(rasl({
  handler: async (cid, method) {
    // returning falsy is 404
    if (cid !== 'bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi') return false;
    // for head, return true if you have it
    if (method === 'head') return true;
    return { content: 'Hello world!' };
  },
));

The rasl() middleware is configured with an object that has a mandatory handler field. The handler is an async function that accepts a cid, which is expected to be a DASL CID (but that isn't validated, if it's invalid it shouldn't match any content you have anyway) and method, which is either get or head.

The return values of the handler may be:

  • anything falsy: this is a 404.
  • true: the content exists (only valid for head requests).
  • object: this must have one of redirect, content, or stream. (If it has several, they are accepted in that order.) If the method was head, these are all treated the same (returning an empty 200). For get:
    • redirect: this sends a 307 redirect to the URL that matches this CID.
    • content: a string, Uint8Array, or Buffer with the content matching this CID.
    • stream: a Readable stream with the content matching this CID.

Note that rasl does not check that the content you provide does indeed match the CID. That is, ultimately, the responsibility of the client.

Serving a directory

A common usage pattern is to serve a directory. To make this easy, we provide a built-in handler that watches a directory and will handle CID lookup correctly even as the content of the directory (recursively) updates.

Note that, in order to do so, it has to read all of the content of the directory (including reading every file to generate a CID). This method is therefore not appropriate to serve directories with many files or huge ones. For that, you'll want to pre-index the CID-to-file mapping and write a custom handler.

import rasl, { makeWatchingHandler } from '@dasl/rasl';
import express from 'express';

const app = express();
app.use(rasl({
  handler: await makeWatchingHandler(absolutePathToYourWebRoot),
));

The handler returned by makeWatchingHandler() also supports a stop() method that you can call if you want it to stop watching. You can use this for two reasons:

  1. You know that the directory won't change. The handler will still work to look up CIDs but will stop watching the directory.
  2. You need to wind the process down cleanly. If you don't stop the handler, it will keep the event loop alive.

Use it like so:

const handler = await makeWatchingHandler(absolutePathToYourWebRoot);
app.use(rasl({ handler ));

// whenever you want to stop
await handler.stop();

RASL Fetch

import { raslFetch } from '@dasl/rasl';

const res = await raslFetch(`web+rasl://bafkreifn5yxi7nkftsn46b6x26grda57ict7md2xuvfbsgkiahe2e7vnq4;berjon.com,bumblefudge.com/`);
if (res.ok) console.log(await res.text());

raslFetch() is an equivalent of fetch() that fetches RASL data. If you pass it a non-RASL URL, it just calls fetch() instead. It only supports GET and HEAD, and it will override a number of options that don't make sense in a RASL context. It only supports the HTTP resolution method of RASL.

In addition to fetch()'s options, it supports:

  • hints: an array of hosts to try fetching from. All hosts are raced until one returns a success code. By default, both the hints in the URL and those in the options are tried.
  • overrideHints: a boolean indicating that the hints included in the URL must be ignored and only those given in hints should be used.
  • skipVerification: a boolean indicating that the retrieved data must not be checked to see if it matches the given CID. NOTE: This is NOT recommended. You gain some speed but you lose the value of using content addressing in the first place. Use at your own risk.

RASL URLs

import { RASLURL } from '@dasl/rasl';

const url = new RASLURL(`web+rasl://bafkreifn5yxi7nkftsn46b6x26grda57ict7md2xuvfbsgkiahe2e7vnq4;berjon.com,bumblefudge.com/`);
console.log(url.cid); // bafkreifn5yxi7nkftsn46b6x26grda57ict7md2xuvfbsgkiahe2e7vnq4
console.log(url.hints); // ['berjon.com', 'bumblefudge.com']

RASLURL is a subclass of URL that exposes a cid getter/setter (for the CID part) and a hints getter/setter that's an array of hints, possibly empty.