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)
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>
Check out the defjs.org to get started.
Package | Version |
---|---|
@defjs/core |
- 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)