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

service-creator

v0.5.2

Published

A simple abstraction to create "services", plain objects that can be used to perform fetch calls in a convention over configuration fashion.

Readme

NPM Version License: MIT CI

service-creator

A simple abstraction to create "services" — plain objects with typed async methods that perform fetch calls, using convention over configuration.

Installation

npm install service-creator

Usage

Define your service endpoints with createEndpoint<TResponse, TArgs?>() for full type safety:

import { createService, createEndpoint } from 'service-creator';

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

const fetcher = {
  fetch: async (url, opts) => {
    const resp = await fetch(url, opts);
    return resp.json();
  },
};

const userService = createService({
  endpoints: {
    // No args — just one generic for the response type
    listUsers: createEndpoint<User[]>({
      url: '/v1/users',
    }),

    // With args — response type first, then args type
    getUser: createEndpoint<User, { id: string }>({
      url: ({ id }) => `/v1/users/${id}`,
    }),

    // POST with body
    createUser: createEndpoint<User, { name: string }>({
      url: '/v1/users',
      method: 'POST',
      body: (args) => args, // args is typed as { name: string }
    }),

    // Response transformation
    getUserName: createEndpoint<string, { id: string }>({
      url: ({ id }) => `/v1/users/${id}`,
      transform: (data) => data.name, // raw response → typed return value
    }),
  },
  basePath: 'https://api.example.com',
  fetcher,
});

// All types are fully inferred:
const users = await userService.listUsers();                  // User[]
const user = await userService.getUser({ id: '123' });        // User
const created = await userService.createUser({ name: 'Ali' });// User
const name = await userService.getUserName({ id: '123' });    // string

createEndpoint<TResponse, TArgs?, TError?>

| Generic | Description | Default | |---|---|---| | TResponse | Return type (Promise<TResponse>) | any | | TArgs | Input parameter type. Omit for no-arg endpoints. | void | | TError | Error type (available via InferError) | Error |

Descriptor options

| Option | Type | Description | |---|---|---| | url | string \| (args: TArgs) => string | Endpoint URL — static or dynamic | | method | HttpMethod | HTTP method (GET, POST, PUT, DELETE, etc.) | | body | object \| (args: TArgs) => any | Request body — static or computed from args | | headers | object \| (args: TArgs) => any | Request headers — static or computed from args | | params | object \| (args: TArgs) => any | Query string params — static or computed from args | | fetchOpts | FetchOptions | Additional fetch options (credentials, mode, etc.) | | transform | (data: any) => TResponse | Transform the raw response before returning |

Custom error types

interface ApiError {
  code: number;
  message: string;
}

const service = createService({
  endpoints: {
    riskyCall: createEndpoint<Data, { id: string }, ApiError>({
      url: ({ id }) => `/v1/data/${id}`,
    }),
  },
  fetcher,
});

Alternative styles

Plain descriptors (types inferred from function signatures):

const service = createService({
  endpoints: {
    getUser: {
      url: (id: string) => `/v1/users/${id}`,
      transform: (data: any): User => data,
    },
  },
  fetcher,
});

Legacy explicit interface:

interface MyService {
  getUser: (id: string) => Promise<User>;
}

const service = createService<MyService>({
  endpoints: {
    getUser: { url: (id: string) => `/v1/users/${id}` },
  },
  fetcher,
});

License

MIT