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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zodified-api/core

v2.3.2

Published

A type-safe API client and server library using Zod

Readme

ZodifiedAPI

ZodifiedAPI is a library that provides a type-safe, framework-agnostic solution for building and consuming APIs using TypeScript. It features an interface similar to Zodios but wraps around fetch instead of axios. Additionally, it includes a powerful mocking feature that is particularly useful for testing and development.

Features

  • Type Safety: Ensures type safety throughout your API, from request validation to response handling.
  • Plugin Support: Easily add and manage middleware functions with support for custom plugins.
  • Zod Integration: Leverages Zod for schema validation, making it easy to define and validate your API schemas.
  • Framework Agnostic: Provides a generic API server class that can be integrated with common server frameworks.
  • Mocking Capabilities: Use the useMock function to simulate API responses during testing or development.
  • Fetch Wrapper: Unlike Zodios, ZodifiedAPI wraps around fetch instead of axios.
  • Retry Mechanism: Includes automatic retry functionality for network errors and temporary server issues.

Installation

You can install the library via npm:

npm install @zodified-api/core

or via yarn:

yarn add @zodified-api/core

Usage

1. Define API Configuration

First, define your API configuration using zod for schema validation.

import { z } from 'zod';
import { makeApi, makeEndpoint } from '@zodified-api/core';

const userSchema = z.object({
  id: z.number(),
  name: z.string(),
});

const getUser = makeEndpoint({
  method: 'get',
  path: '/user',
  alias: 'getUser',
  description: 'Get user',
  parameters: [
    {
      type: 'Query',
      name: 'id',
      schema: z.number(),
      description: 'User ID',
    },
  ],
  response: userSchema,
});

export const api = makeApi([getUser]);

2. Create an API Client

Based on the API configuration, you can create a type-safe API client.

import { Zodified } from '@zodified-api/core';
import { api } from './api-config';

const ApiClient = new Zodified('https://api.example.com', api);

const userData = await ApiClient.get('/user', { queries: { id: 1 } });
console.log(userData); // { id: 1, name: 'John Doe' }

3. Using the Mocking Feature

The useMock function allows you to simulate API responses, which is useful during testing or when the backend is not yet implemented.

ApiClient.useMock({
  get: {
    '/user': {
      response: { id: 1, name: 'John Doe' },
      delay: 100,
    },
  },
  post: {
    '/user': {
      response: { id: 2, name: 'Jane Doe' },
    },
  },
}, 500); // Adds a 500ms delay

4. Making Requests

ZodifiedAPI allows you to make requests to API endpoints using methods like get, post, put, patch, and delete.

const updatedUser = await ApiClient.put('/user', { payload: { id: 1, name: 'New Name' } });
console.log(updatedUser); // { id: 1, name: 'New Name' }

API Reference

makeApi(endpoints: ZodifiedEndpointDefinition[])

Creates an API configuration object based on the provided endpoint definitions.

makeEndpoint(config: ZodifiedEndpointConfig)

Defines an API endpoint. You can specify the HTTP method, path, validation schema, and more.

Zodified

A class for making type-safe API requests.

  • Methods:
    • get(path: string, config?: RequestConfig): Sends a GET request to the specified API endpoint and returns a type-safe response.
    • post(path: string, data: object, config?: RequestConfig): Sends a POST request to the specified API endpoint and returns a type-safe response.
    • put(path: string, data: object, config?: RequestConfig): Sends a PUT request to the specified API endpoint and returns a type-safe response.
    • patch(path: string, data: object, config?: RequestConfig): Sends a PATCH request to the specified API endpoint and returns a type-safe response.
    • delete(path: string, config?: RequestConfig): Sends a DELETE request to the specified API endpoint and returns a type-safe response.
    • useMock(mockData: MockData<Api>, delay?: number): Uses mock data to simulate API responses.

Contributing

Contributions are welcome! Feel free to submit a Pull Request or open an Issue.

License

This project is licensed under the MIT License.