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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tapid

v0.0.1

Published

A human-first type framework for describing API services.

Downloads

4

Readme

Tapid

Tapid (TypeScript API Document) is a human-first type framework for describing API services.

Motivation

API documents are essential part of any service design. They help us disover, understand, reason, and test the implementations. Existing API document formats, however, are either machine-generated, archaic, or obsolete algother.

Tapid attempts to solve this problem by providing not a format but a framework on top of TypeScript to describe API services similar to how one would using OpenAPI.

Why TypeScript?

Tapid uses TypeScript as the language to describe APIs. This means you describe your APIs using namespaces, interfaces, and types.

The purpose of any API specification is to describe what a service does: what endpoints it has, what requests it expects, and what responses it returns. Turns out, all of these are types! Instead of inventing yet another specification language, we've decided to rely on the one already used by many—TypeScript.

In addition, using TypeScript for API description has the following benefits:

  1. Easier adoption. Your team can use the same language they are using already, no need to learn a new one.
  2. Reusability. You can import your API description anywhere in your code base directly, no generation step needed:
// src/components/Cart.tsx
//            👇 Import the API document.
import type { CartService } from '~/api/services/cart'

interface CartProps {
  items: CartService.CartItem[]
  //     👆 Reference API types directly
  //       because it's regular TypeScript!
}

export function Cart(props: CartProps) {
  /* ... */
}
  1. Type-safety. Writing API document in TypeScript means the document itself is type-safe! Tapid provides a framework to make sure the requests and responses you describe actually make sense.
  2. Rich feature set. Types, references, unions—you get all of TypeScript features for free (and we don't have to design abstractions just to support those).

Example

Here's an example of a cart service API described using Tapid:

// services/user.ts

export declare namespace CartService {
  const version = '1.0'

  interface Cart {
    items: CartItem[]
  }

  interface CartItem {
    id: string
    title: string
    quantity: number
  }

  /**
   * Return the current cart.
   */
  interface GET
    extends Endpoint<
      '/cart',
      {},
      {
        200: Response.json<Cart>
      }
    > {}

  /**
   * Return a cart item by ID.
   */
  interface GET
    extends Endpoint<
      '/cart/:itemId',
      {
        // Request path parameters are inferred
        // from the endpoint URL. Type-safety
        // on the specification level!
        parameters: { cartId: string }
      },
      {
        // Describe different response scenarios.
        200: Response.json<CartItem>
        400: Response.text<'Invalid cart ID'>
        404: Response.text<'Cart item not found'>
      }
    > {}

  /**
   * Add a new item to the cart.
   */
  interface POST
    extends Endpoint<
      '/cart',
      {
        // Request must provide a FormData representing
        // the cart item to add to the cart.
        body: Request.formData<CartItem>
      },
      {
        201: Response.json<CartItem>
        400: Response.text<'Invalid cart item'>
      }
    > {}

  /**
   * Delete a cart item by ID.
   */
  interface DELETE
    extends Endpoint<
      '/cart/:itemId',
      {
        parameters: { itemId: string }
      },
      {
        200: Response.json<CartItem>
        400: Response.text<'Invalid cart ID'>
        404: Response.text<'Cart item not found'>
      }
    > {}
}

Tapid exposes types like Endpoint, Request, and Response globally for all of your API documents.