https://github.com/defjs/defjs
👏 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.
https://github.com/defjs/defjs
ajax fetch http http-client http-stream javascript openapi swagger typescript wechat-mini-program xmlhttprequest
Last synced: about 1 month ago
JSON representation
👏 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.
- Host: GitHub
- URL: https://github.com/defjs/defjs
- Owner: defjs
- License: mit
- Created: 2024-06-12T01:44:50.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-03-19T03:01:55.000Z (about 2 months ago)
- Last Synced: 2025-03-30T22:19:29.966Z (about 1 month ago)
- Topics: ajax, fetch, http, http-client, http-stream, javascript, openapi, swagger, typescript, wechat-mini-program, xmlhttprequest
- Language: TypeScript
- Homepage: https://defjs.org
- Size: 522 KB
- Stars: 44
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
## 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](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/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
```shell
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**
```javascript
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({
id: field().withParam()
})/**
* @title Step 3
* @file src/pages/home.ts
* @description Use defined requests in business code
*/
const { doRequest } = useGetUser();
const { error, body } = await doRequest({id: 1});
if (error) {
console.error(error);
return;
}
console.log(body);
```## Documentation
Check out the [🚧 defjs.org](https://defjs.org) to get started.
## Packages
| Package | Version |
|------------------------------|:---------------------------------------------------------------------------------------------|
| [@defjs/core](packages/core) |  |
| [@defjs/angular](packages/angular) |  |## Roadmap
- Documentation official website
- Wechat mini programs handler
- CLI Tool
- Generate API from OpenAPI
- Generate Full SDK Package (Like the [S3 SDK](https://www.npmjs.com/package/@aws-sdk/client-s3))
- Vue wrapper package
- React wrapper package
- Think about simplifying useXXX and doRequest## License
[MIT](LICENSE)
## Reference
- [Angular HttpClient](https://angular.dev/guide/http)
- [Axios](https://axios-http.com)
- [Zod](https://zod.dev)
- [Deepkit Framework](https://github.com/deepkit/deepkit-framework)
- [tRPC](https://trpc.io)
- [Google API design guide](https://cloud.google.com/apis/design)
- [Tanstack Query](https://tanstack.com/query)
- [Rxjs](https://rxjs.dev)