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

clyent

v0.1.6

Published

TypeScript Axios API client & service builder with interceptor and metadata support

Downloads

8

Readme

clyent

A lightweight TypeScript library for rapidly building Axios-based API clients with fully-typed service definitions, endpoint metadata, and built-in interceptor support.


Features

  • Service-Centric Definition: Group endpoints under named ApiService instances with per-service baseUrl, config, and interceptors.
  • Strong Typing: Inferred method signatures and return types based on your endpoint definitions.
  • Metadata Exposure: Every service client exposes baseUrl, merged config, and the underlying Axios instance for advanced use cases.
  • Global & Service-Level Interceptors: Plug in request/response hooks at both global and per-service levels.
  • Zero Runtime Overhead: Just a thin factory wrapping Axios—no heavy abstractions.

Installation

npm install clyent axios
# or
yarn add clyent axios

Make sure you also install axios (peer dependency).


Basic Usage

1. Define Your Services

Create one or more ApiService instances, each with a unique name, optional baseUrl, and a factory for your endpoint methods.

import { ApiService } from 'clyent';
import { AxiosInstance } from 'axios';

// Example response types
interface User {
  id: number;
  username: string;
}
interface GetUsersResponse {
  items: User[];
}

export const usersService = new ApiService({
  name: 'users',
  baseUrl: '/users',
  endpoints: (instance: AxiosInstance) => ({
    getUsers: (page: number, limit: number) => instance.get<GetUsersResponse>('/', { params: { page, limit } }),
    getUser: (id: number) => instance.get<User>(`/${id}`),
  }),
});

2. Create the API Client

Use createApiClient with a root URL and a map of your services.

import { createApiClient } from 'clyent';

const api = createApiClient('https://api.example.com', {
  config: {
    headers: { 'Content-Type': 'application/json' },
  },
  interceptors: {
    request: {
      onFulfilled: (cfg) => {
        /* add auth token */ return cfg;
      },
    },
  },
  services: {
    users: usersService,
    // ...other services
  },
});

3. Consume Endpoints & Metadata

// Call an endpoint
api.users.getUsers(1, 20).then(res => {
  console.log(res.data.items);
});

// Access service metadata
console.log(api.users.baseUrl);      // "/users"
console.log(api.users.config.baseURL); // "https://api.example.com/users"

// Use raw Axios instance
api.users.instance.interceptors.response.use(...);

Advanced Topics

  • Global vs. Service-Level Interceptors: Pass interceptors in createApiClient for all services, or on individual ApiService definitions for fine-grained control.
  • Extensibility: Because you own the raw Axios instance (api[service].instance), you can add retries, caching, or custom plugins on the fly.
  • Type Safety: No need to cast; each endpoint’s parameters and res.data are fully inferred from your definitions.

API Reference

new ApiService<Endpoints>(cfg: ApiServiceConfig<Endpoints>)

  • cfg.name: string — service key, becomes api[name].
  • cfg.baseUrl: string — URL segment appended to root.
  • cfg.config: AxiosRequestConfig — merged with global.
  • cfg.interceptors: Interceptors — request/response hooks for this service.
  • cfg.endpoints: (instance: AxiosInstance) => Endpoints — factory returning your typed methods.

createApiClient(rootUrl: string, init: ApiClientConfig)

  • rootUrl: Base URL for all services.
  • init.config: Global Axios config.
  • init.interceptors: Global interceptors.
  • init.services: Map of service keys → ApiService instances.

Returns an object typed as:

{ [K in keyof Services]: ServiceClient<Endpoints> }

Where ServiceClient<Endpoints> exposes:

  • All your endpoints methods
  • baseUrl, config, instance, interceptors

Contributing

  1. Fork the repo
  2. Install dependencies: npm install
  3. Build: npm run build
  4. Create a PR—happy to review!

License

MIT