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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@spilne/perfect-http

v0.2.0

Published

HTTP client on the Perfect effect runtime — typed errors, retries, streaming (SSE/NDJSON), mockable transport.

Readme

@spilne/perfect-http

Typed-effect HTTP client for @spilne/perfect-core. Three tiers of fetch, a configurable client with middleware, retry with full outcome control, native streaming (text / lines / NDJSON / SSE), typed error response bodies, and a test-double mock — every request returns Eff<A, Throws<HttpClientError>>, so failures are visible in the type and handled with .catch / .catchTag.

Install

bun add @spilne/perfect-http

Not yet published to npm — install from the workspace for now.

Quickstart

import { succeed } from "@spilne/perfect-core";
import { DefaultHttpClient, type ResponseParser } from "@spilne/perfect-http";

interface User {
  id: number;
  name: string;
}

// Any { safeParse } object works — zod schemas satisfy this directly.
const UserSchema: ResponseParser<User> = {
  safeParse: (d: unknown) =>
    d !== null &&
    typeof d === "object" &&
    "id" in d &&
    "name" in d &&
    typeof d.id === "number" &&
    typeof d.name === "string"
      ? { success: true, data: { id: d.id, name: d.name } }
      : { success: false, error: "not a User" },
};

const client = new DefaultHttpClient({
  baseUrl: "https://api.example.com",
  headers: { authorization: "Bearer xyz" },
});

// fetch → status check → JSON → schema, as one typed effect
const user = await client.get("/users/1", UserSchema).orDie().run();

// errors are tagged — handle them in the type
const safe = client
  .get("/users/1", UserSchema)
  .catchTag("HttpStatusError", (e) => succeed({ id: -1, name: `(status ${e.status})` }));

client.withOverrides({ headers: { "x-trace": "t-123" } }) derives a client — headers spread-merge, everything else falls back to the base.

Three tiers of fetch

Below the client sit three free functions, composing upward:

| Tier | Function | Adds | | ---- | ----------------------------------------------------- | ---------------------------------------------- | | 1 | httpFetch | raw Response through a transport — no checks | | 2 | httpFetchOk | status check → HttpStatusError on non-2xx | | 3 | httpRequest / httpRequestJson / httpRequestText | body decode + schema parse |

Every request flows through an HttpTransport (default: globalThis.fetch) — pass your own to mock, proxy, or instrument.

Features

  • Typed errorsHttpNetworkError, HttpTimeoutError, HttpStatusError, HttpParseError, HttpUnknownError; HTTP_RETRYABLE lists the transient tags
  • ClientDefaultHttpClient with baseUrl, default headers, .get/.post/.put/.patch/.delete, withOverrides, HttpMiddleware hooks (onRequest / onResponse / onError)
  • DIHttpClientService tag for Layer-based injection
  • RetrywithRetryAll, withRetryAllBy, and retryHttp for HTTP-ready transient defaults; Retry namespace mirrors these as Retry.all, Retry.allBy, and Retry.http; for polling use core's .repeatUntil / .repeatUntilWithBackoff.
  • StreaminghttpStream base plus httpStreamText / httpStreamLines / httpStreamNDJSON / httpStreamSSE, and composable parseSSE / parseNDJSON pipes
  • TestingMockHttpClient / mockHttpClient: route-matched test double with call recording

Links

  • Repo: https://github.com/spilne/perfect
  • Full guide: documentation/13-http.md
  • Runnable examples: examples/
  • OpenTelemetry tracing for this client: @spilne/perfect-http-otel