defjs
0.3.0
def
merupakan singkatan dari define
, jadi bisa dibaca define js
.
Defjs adalah perpustakaan yang membantu Anda menentukan dan memulai permintaan, yang bertujuan untuk memudahkan Anda menentukan permintaan tanpa mengkhawatirkan detailnya.
Gunakan untuk manajer paket
npm install @defjs/core
// or
yarn install @defjs/core
// or
pnpm install @defjs/core
// or
bun install @defjs/core
Gunakan untuk CDN
Hanya dapat menggunakan modul ES
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 ) ;
Lihat ? defjs.org untuk memulai.
Kemasan | Versi |
---|---|
@defjs/inti | |
@defjs/angular |
MIT