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

@resq-sw/http

v0.1.1

Published

Effect-based HTTP client with retry, timeout, and schema validation

Readme

@resq-sw/http

Effect-based HTTP client with retry, timeout, schema validation, and security middleware.

Installation

bun add @resq-sw/http effect

Peer dependency: effect.

Quick Start

import { get, post } from "@resq-sw/http";
import { Effect } from "effect";
import { HttpClient } from "effect/unstable/http";

const program = Effect.gen(function* () {
  const users = yield* get<User[]>("/api/users");
  const created = yield* post<User>("/api/users", { name: "Alice" });
  return { users, created };
});

// Run with the default HTTP client
Effect.runPromise(program.pipe(Effect.provide(HttpClient.layer)));

API Reference

fetcher(url, method?, options?, params?, body?)

Core HTTP function. All convenience methods delegate to this.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | url | string | required | URL path or absolute URL | | method | HttpMethod | "GET" | HTTP method | | options | FetcherOptions<T> | {} | Request options | | params | QueryParams | -- | Query parameters | | body | RequestBody | -- | Request body (POST/PUT/PATCH only) |

Returns Effect.Effect<T, FetcherError | FetcherValidationError, HttpClient.HttpClient>.

URL resolution: absolute URLs are used as-is; relative paths are prefixed with VITE_SITE_URL, SITE_URL, or http://localhost:5173.

FetcherOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | retries | number | 0 | Retry count on failure | | retryDelay | number | 1000 | Base delay between retries (exponential backoff) | | timeout | number | 10000 | Request timeout in ms | | headers | Record<string, string> | {} | Additional request headers | | schema | Schema.Schema<T> | -- | Effect Schema for response validation | | onError | (error: unknown) => void | -- | Error callback | | signal | AbortSignal | -- | Abort signal | | bodyType | "json" \| "text" \| "form" | "json" | Request body encoding |

Retry Behavior

  • Uses exponential backoff starting from retryDelay.
  • Always retries: 429 (rate limit), 5xx, network errors, timeouts.
  • Never retries: validation errors, 4xx (except 429).

Convenience Methods

All return Effect.Effect<T, FetcherError | FetcherValidationError, HttpClient.HttpClient>.

| Function | Signature | |----------|-----------| | get | (url, options?, params?) => Effect | | post | (url, body?, options?, params?) => Effect | | put | (url, body?, options?, params?) => Effect | | patch | (url, body?, options?, params?) => Effect | | del | (url, options?, params?) => Effect | | options | (url, options?, params?) => Effect | | head | (url, options?, params?) => Effect |

All methods support schema overloads for compile-time type safety:

import { Schema } from "effect";

const UserSchema = Schema.Struct({ id: Schema.Number, name: Schema.String });

const user = get("/api/users/1", { schema: UserSchema });
// Type: Effect<{ id: number; name: string }, ...>

Schema Helpers

createPaginatedSchema(itemSchema)

Creates a schema for paginated API responses.

const PagedUsers = createPaginatedSchema(UserSchema);
// { data: User[], pagination: { page, pageSize, total, totalPages } }

createApiResponseSchema(dataSchema)

Creates a schema for standard API responses.

const ApiUser = createApiResponseSchema(UserSchema);
// { success: boolean, data: User, message?: string, errors?: string[] }

Error Types

FetcherError

Thrown on network errors, timeouts, and non-2xx responses.

| Property | Type | Description | |----------|------|-------------| | message | string | Error description | | url | string | Request URL | | status | number? | HTTP status code | | responseData | unknown? | Response body if available | | attempt | number? | Retry attempt number |

FetcherValidationError

Thrown when response data fails schema validation.

| Property | Type | Description | |----------|------|-------------| | message | string | Error description | | url | string | Request URL | | problems | string | Schema validation errors | | responseData | unknown | Raw response data | | attempt | number? | Retry attempt number |

Security Utilities

shouldRedirectToHttps(protocol, url, headers, nodeEnv?): string | null

Checks if a request should be redirected to HTTPS. Handles proxy headers (x-forwarded-proto, x-forwarded-ssl). Returns the HTTPS URL or null.

  • Skipped in development and test environments.
const redirect = shouldRedirectToHttps("http", req.url, req.headers);
if (redirect) return Response.redirect(redirect, 301);

getRequestId(existingId?): string

Returns the existing request ID or generates a new UUID.

const reqId = getRequestId(headers["x-request-id"]);

License

Apache-2.0