quick fetch api
v2.0.0 Release
Quick-Fetch-API是一個簡約的HTTP客戶端,旨在輕鬆和異步請求。它提供了直接的界面,簡化了HTTP操作,以獲得無縫的開發人員體驗。
EasyFetch類,用於處理HTTP請求的更用戶友好的方法。 使用NPM安裝軟件包:
npm install quick-fetch-api const EasyFetch = require ( 'quick-fetch-api' ) ;
// Example usage
const apiUrl = 'https://api.example.com' ;
const api = new EasyFetch ( apiUrl , {
'Content-Type' : 'application/json' ,
// Add headers if any
} ) ;
// GET request example
api . get ( {
url : '/data' ,
callback : ( { loading , data , error } ) => {
if ( loading ) {
console . log ( 'Loading...' ) ;
} else if ( data ) {
console . log ( 'Data:' , data ) ;
} else {
console . error ( 'Error:' , error ) ;
}
} ,
} ) ;
// POST request example
const postData = { key : 'value' } ;
api . post ( {
url : '/create' ,
data : postData ,
callback : ( { loading , data , error } ) => {
if ( loading ) {
console . log ( 'Loading...' ) ;
} else if ( data ) {
console . log ( 'Response:' , data ) ;
} else {
console . error ( 'Error:' , error ) ;
}
} ,
} ) ;
// {like that you can do PUT,PATCH,DELETE} 該項目是根據MIT許可證獲得許可的 - 有關詳細信息,請參見許可證文件。
根據您的特定項目詳細信息,請隨時修改或進一步增強它。