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

@selfage/web_service_client

v3.3.5

Published

HTTP Client to make remote call to services from browsers.

Readme

@selfage/web_service_client

Send HTTP request from browser with strongly typed interfaces without touching raw response parsing.

Why @selfage/web_service_client?

@selfage/web_service_client is the browser companion to @selfage/generator_cli. The generator emits strongly typed TypeScript descriptors for your remote calls, and this package lets you invoke them without touching raw response parsing.

Simply send the generated request factories through client.send() and receive typed responses. Avoid hand-written DTOs and unchecked fetch calls by relying on descriptors for serialization.

The @selfage/generator_cli README shows how a single YAML definition yields service descriptors, handler interfaces, and message types. Once you have that output, this package handles everything else.

How to use it

1. Model your API once

Describe your enums, messages, services, and remote calls in YAML and generate the TypeScript descriptors:

npm install --save-dev @selfage/generator_cli
npx geneage ./definition.yaml

The emitted files expose RemoteCallDescriptor objects and helper factories (see test_data/ for examples).

2. Install the runtime client

npm install @selfage/web_service_client

3. Instantiate a client with session persistence

Provide a SessionStorage implementation (use LocalSessionStorage for browser localStorage, or roll your own):

import { WebServiceClient } from "@selfage/web_service_client";
import { LocalSessionStorage } from "@selfage/web_service_client/local_session_storage";

const client = WebServiceClient.create(
  new LocalSessionStorage(),
  "https://api.example.com",
);

client.on("unauthenticated", async () => {
  // Trigger a re-login flow after the server returns 401.
});
client.on("httpError", (error) => {
  console.error("Request failed", error.statusCode, error.message);
});

The client automatically injects and clears the session header defined in your generated descriptor (for example authKey: "u").

4. Send strongly typed requests

Use the generated factory functions to keep request and response payloads type-safe end-to-end:

import { newGetHistoryRequest } from "./generated/get_history";

const response = await client.send(
  newGetHistoryRequest({ page: 1 }),
  { retries: 3, timeout: 5_000, keepAlive: true },
);

console.log(response.videos); // Typed as string[]

Binary bodies and metadata are also covered. For instance, the generated newUploadFileRequest combines a Blob body with structured metadata, and the client serializes everything according to the descriptor.

Advanced options

  • keepAlive, retries, and timeout are available per call through WebClientOptions for fine-grained transport tuning.
  • Subscribe to the "error" event to centralize logging of any failure (HTTP or network).
  • Implement the SessionStorage interface to plug in cookies, memory stores, or cross-tab synchronization strategies for authentication.
  • Pair with @selfage/message helpers for assertions and rich test coverage (see client_test.ts for end-to-end scenarios).