api-typing
TypeScript icon, indicating that this package has built-in type declarations

1.10.0 • Public • Published

api-typing

npm version

api-typing


English | 简体中文

A strong type-hint http client framwork(based on axios).

Dear front-end colleagues, are you fed up with the interface with the back-end every day, adjusting the interface path and parameter transfer format? Tired of viewing backend documentation? Are you tired of checking and synchronizing the interface field changes after each update? It's time to make these jobs a little easier.

Install

pnpm i api-typing

Usage

  1. set a script to run get-types in package.json

    {
      "scripts": {
        "get-types": "get-types \"https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore-expanded.json\" \"./api-typing-meta.d.ts\""
      }
    }

    the first argument is a openapi definition file, json format. the second argument is auto-generated type definetion file name with default value api-typing-meta.d.ts

  2. run

    pnpm run get-types

    the type definition file would be generated in your project root.

  3. after api-typing-meta.d.ts gengrated in your project root. make sure your tsconfig.json include this declare.

    {
      "include": ["api-typing-meta.d.ts"]
    }
  4. import and enjoy it!

    import { createHTTPClient } from "api-typing"
    createHTTPClient({ baseURL: "your baseURL" })
      .post("choose/url/with/hint", {
        /**
         * request field with type-hint
         */
      })
      .then((d) => {
        /**
         * response field with type-hint
         */
      })

Package Sidebar

Install

npm i api-typing

Weekly Downloads

5

Version

1.10.0

License

MIT

Unpacked Size

95.5 kB

Total Files

28

Last publish

Collaborators

  • yinzhenyu