Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

119 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-typing

npm version

api-typing


English | 简体中文 | DeepWiki

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
         */
      })

About

Axios based HTTP client with type hint

Topics

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages