New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@simple-api/core

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@simple-api/core

Framework-agnostic fetch-based API engine

latest
npmnpm
Version
1.0.8
Version published
Maintainers
1
Created
Source

simple-api logo

@simple-api/core

The high-performance, framework-agnostic engine powering simple-api.

@simple-api/core is a production-grade API client builder designed for high-scale TypeScript applications. It provides a service-oriented architecture, built-in request deduplication, a powerful tiered middleware system, and automatic parameter injection.

Core Features

  • Interceptors: Global hooks for onRequest, onResponse, and onError.
  • PWA Caching: Built-in Stale-While-Revalidate support via Web Cache API.
  • Polling: Native background auto-refresh for any endpoint.
  • File Uploads: Automatic conversion and header management for multipart/form-data.
  • Structured Errors: Rich ApiError class with status codes and full response bodies.
  • Request Timeouts: Built-in AbortController support.
  • Deduplication: Automatic merging of concurrent identical GET requests.

Installation

npm install @simple-api/core

Quick Start

1. Define your API

import { createApi } from "@simple-api/core";

export const api = createApi({
  baseUrl: "https://api.example.com",
  services: {
    users: {
      get: { method: "GET", path: "/users/:id" },
      update: { method: "PATCH", path: "/users/:id" },
    },
  },
});

2. Make Calls

// Path parameters and types are automatically handled
const user = await api.users.get({ params: { id: "123" } });

// File uploads made easy
await api.users.update({
  params: { id: "123" },
  upload: true,
  body: { avatar: fileInput.files[0] },
});

Technical Deep Dive

Interceptors

Interceptors fire at specific execution points, regardless of your middleware stack.

const api = createApi({
  interceptors: {
    onRequest: (ctx) => {
      console.log(`Starting ${ctx.service}.${ctx.endpoint}`);
      return ctx.options;
    },
    onResponse: (data) => data.payload ?? data,
  },
  ...
});

PWA Caching (SWR)

import { createCacheMiddleware } from "@simple-api/core";

const api = createApi({
  middleware: [createCacheMiddleware({ swr: true, ttl: 3600000 })],
  ...
});

Native Polling

// Re-fetch automatically every 5 seconds
api.users.list({ pollingInterval: 5000 });

Middleware System

SimpleAPI uses a Koa-style async (context, next) middleware system.

  • Global: Runs on every request.
  • Service: Runs on every request to a specific service.
  • Endpoint: Runs only on a specific endpoint.

Error Handling

When a request fails, the engine throws an ApiError.

import { ApiError } from "@simple-api/core";

try {
  await api.users.get({ params: { id: "999" } });
} catch (error) {
  if (error instanceof ApiError) {
    console.error(error.status, error.data);
  }
}

License

MIT © Elnatan Samuel

FAQs

Package last updated on 14 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts