Hey API

repository·main·Indexed 26 days ago

https://github.com/hey-api/hey-api

An ecosystem of tools that converts OpenAPI and JSON Schema specifications into production-ready code, including SDKs, validation schemas, and framework-specific hooks. The suite includes @hey-api/openapi-ts for TypeScript, @hey-api/openapi-python for Python SDKs and Pydantic models, a JSON Schema $Ref Parser, and a Nuxt module for seamless integration.

Tokens
80.2K
Snippets
297
Records
600
Agent score
90%

What's inside hey-api

  1. Overview of Hey API HTTP Clients

    main

    Hey API provides a variety of HTTP clients that are seamlessly integrated with the @hey-api/openapi-ts ecosystem. Instead of forcing a specific technology, Hey API supports multiple client implementations, allowing you to use the one that best fits your project.

    Key features include:

    • Type-safe response data and errors.
    • Response data validation and transformation.
    • Access to original requests and responses.
    • Granular customization options for requests and responses.
    • Support for bundling inside the generated output.
    • Minimal learning curve by extending the underlying technology you already use.
  2. Overview of Hey API ecosystem

    main
    Hey API is an ecosystem designed to transform API specifications (like OpenAPI) into production-ready code. It provides tools for generating SDKs, schemas, and hooks across different programming languages and frameworks.
  3. Understand the generated output structure

    main

    When using @hey-api/openapi-ts with default configuration, the generator produces a set of files in your specified output directory. These files include the client, the SDK, and TypeScript types. The structure typically looks like this:

    • client.gen.ts: The generated client instance.
    • sdk.gen.ts: The generated SDK methods.
    • types.gen.ts: The generated TypeScript types.
    • index.ts: A convenience entry file that re-exports the generated artifacts.
    • client/ and core/ folders: Scaffolding used by client plugins to enable HTTP requests.
  4. Understand Hey API Core Plugins

    main

    Hey API uses a plugin-based architecture where 'Core Plugins' serve as the foundation for all other functionality. These core plugins provide the essential primitives that specialized plugins (like framework-specific adapters) reuse. By building on these core artifacts, Hey API ensures a smaller output size and a more consistent developer experience.

    The core plugins include:

    • TypeScript: Handles TypeScript-specific generation logic.
    • SDK: Manages the generation of the SDK structure.
    • Transformers: Handles data transformation logic during the generation process.
    • Schemas: Manages the generation and handling of schemas.
  5. Understand @hey-api/typescript generated artifacts

    main

    The plugin generates types in a types.gen.ts file. These types do not impact bundle size or runtime performance as they are discarded during build time (unless runtime enums are configured).

    Generated types include:

    • Requests: A single type per endpoint containing body, path, query, and url properties. Customize naming/casing via .name and .case options.
    • Responses: A type for all endpoint responses, including a helper type for individual status codes. Customize naming/casing via .name and .case options.
    • Definitions: A type for every reusable definition in your OpenAPI spec. Customize naming/casing via .name and .case options.
  6. Use the Hey API Nuxt Module

    main
    The @hey-api/nuxt module provides a seamless integration for the @hey-api/openapi-ts codegen ecosystem within Nuxt applications. It enables type-safe response data and errors, response data validation and transformation, and granular customization for requests and responses. It also supports bundling inside the generated output.