Skip to content
/ defjs Public

πŸ‘ Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

License

Notifications You must be signed in to change notification settings

defjs/defjs

Repository files navigation

Vite logo


npm package monthly downloads build status license codecov


Introduction

def is an abbreviation for define, so it can be read as define js.

Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

  • Supports multiple request methods such as Fetch, XMLHttpRequest, custom, etc.
  • Functional API.
  • 🚧 Supports streaming. (WIP)
  • Supports JS/TS with complete type.
  • Supports any JS runtime.
  • Supports Interceptors.
  • Supports ESM
  • 🚧 Supports Mini Programs. (WIP)

Quick Start

Use for package manager

npm install @defjs/core
// or
yarn install @defjs/core
// or
pnpm install @defjs/core
// or
bun install @defjs/core

Use for CDN

Only can use ES modules

<script type="module">
  import {createGlobalClient, defineRequest, field} from 'https://unpkg.com/@defjs/core/index.min.js';

  /**
   * @title Step 1
   * @file src/main.ts
   * @description Setting up a global client
   */
  createGlobalClient({
    host: 'https://example.com',
  });

  /**
   * @title Step 2
   * @file src/lib/api/user.ts
   * @description Define the request api request in the lib/api directory of the project
   */
  const useGetUser = defineRequest('/v1/user/:id')
    .withField(
      field(0).withParam()
    )

  /**
   * @title Step 3
   * @file src/pages/home.ts
   * @description Use defined requests in business code
   */
  const { doRequest } = useGetUser();

  await doRequest(1);
</script>

Documentation

Check out the defjs.org to get started.

Packages

Package Version
@defjs/core core version

Roadmap

  • The error handling mechanism for doRequest needs reconsideration
  • Documentation official website
  • Wechat mini programs handler
  • CLI Tool
    • Generate API from OpenAPI
    • Generate Full SDK Package (Like the S3 SDK)

License

MIT

Reference

About

πŸ‘ Defjs is a library that helps you define and initiate requests, aiming to make it easier for you to define requests without worrying about the details.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published