defjs
0.3.0
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.
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
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<number>().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);
Check out the ? defjs.org to get started.
Package | Version |
---|---|
@defjs/core | |
@defjs/angular |
MIT