defjs
0.3.0
def
define
の略称なので、 define js
と読みます。
Defjs は、リクエストの定義と開始を支援するライブラリであり、詳細を気にせずにリクエストを簡単に定義できるようにすることを目的としています。
パッケージマネージャーに使用
npm install @defjs/core
// or
yarn install @defjs/core
// or
pnpm install @defjs/core
// or
bun install @defjs/core
CDNに使用する
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 ) ;
?をチェックしてください。 defjs.org から始めてください。
パッケージ | バージョン |
---|---|
@defjs/コア | |
@defjs/角度 |
マサチューセッツ工科大学