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

requestlane

v0.1.4

Published

Typed, framework-independent HTTP clients with opt-in memory caching and Axios/Fetch transports

Readme

requestlane

npm version npm downloads license

框架无关的 TypeScript HTTP 客户端,提供请求、token 会话与内存缓存管理。

支持 Axios、Fetch、类型端点、Zod 校验、超时与取消。缓存按需开启,使用实例内内存,支持 TTL、并发合并和按标签失效。

安装

npm install requestlane

使用 Fetch

import { createClient } from "requestlane";
import { createFetchTransport } from "requestlane/fetch";

const fetchClient = createClient({
  baseURL: "https://example.com/api",
  transport: createFetchTransport(),
});

const member = await fetchClient.get<{ id: string; name: string }>(
  "/members/1",
);
await fetchClient.post("/members", { name: "Ada" });

使用 Axios

import { createClient as createAxiosClient } from "requestlane";
import { createAxiosTransport } from "requestlane/axios";

const axiosClient = createAxiosClient({
  baseURL: "https://example.com/api",
  transport: createAxiosTransport(),
});

const profile = await axiosClient.get<{ id: string; name: string }>(
  "/members/1",
);
await axiosClient.patch("/members/1", { name: "新名称" });

使用缓存与会话

从 0.1.4 起,可从独立入口导入请求、缓存和会话能力,无须分别安装。

import { createCoreClient, defineEndpoint } from "requestlane/core";
import { createMemoryCache } from "requestlane/cache";
import { createSession } from "requestlane/session";
import { z } from "zod";

// 也可替换为 createFetchTransport()。
const cachedClient = createCoreClient({
  baseURL: "https://example.com/api",
  transport: createAxiosTransport(),
  cache: createMemoryCache({ ttl: 30_000, capacity: 20 }),
});

const memberDetail = defineEndpoint({
  method: "GET",
  path: "/members/:id",
  inputValidators: { params: z.object({ id: z.string() }) },
  validator: z.object({ id: z.string(), name: z.string() }),
  cache: { tags: ["members"] },
});

const first = await cachedClient.call(memberDetail, { params: { id: "1" } });
const second = await cachedClient.call(memberDetail, { params: { id: "1" } });
// 第二次读取命中缓存,输入与响应类型由 schema 推断。
cachedClient.invalidate({ tag: "members" });

const sessionClient = createCoreClient({
  baseURL: "https://example.com/api",
  transport: createAxiosTransport(),
  session: createSession(),
});

sessionClient.setToken("access-token");
await sessionClient.get("/me"); // Authorization: Bearer access-token
await sessionClient.get("/public", { anonymous: true });
sessionClient.clearToken();

同时使用缓存与动态会话:

const auth = { token: "access-token", version: 1 };

const composedClient = createCoreClient({
  baseURL: "https://example.com/api",
  transport: createAxiosTransport(),
  cache: createMemoryCache(),
  session: createSession({
    token: () => auth.token,
    sessionVersion: () => auth.version,
  }),
});

const current = await composedClient.call(memberDetail, {
  params: { id: "1" },
});

登录、退出、换号或权限变化时更新 version;同身份续期只更新 token。客户端根据身份版本隔离缓存与在途结果。

仅使用缓存

import { ReadCache } from "requestlane/cache";

const cache = new ReadCache(30_000, 20);
const answer = await cache.get("answer", async () => 42);

cache.invalidate({ key: "answer" });
cache.clear();

ReadCache 可缓存任意异步结果。

文档

使用文档:快速开始、类型与校验、缓存、会话及完整示例。

链接

npm · 问题反馈 · MIT