katana-client
v1.0.5
Published
A powerful HTTP client module similar to axios
Downloads
2
Readme
KatanaClient
KatanaClient, Node.js için gelişmiş HTTP ve HTTPS istemci kütüphanesi.
Kurulum
npm install katana-client
Kullanım
const KatanaClient = require('katana-client');
const client = new KatanaClient({
timeout: 10000,
maxRedirects: 5,
followRedirects: true,
// Diğer seçenekler
});
HTTP İstekleri
client.get('https://api.example.com/data')
.then(response => {
console.log('GET response:', response);
})
.catch(error => {
console.error('GET error:', error);
});
client.post('https://api.example.com/data', { key: 'value' })
.then(response => {
console.log('POST response:', response);
})
.catch(error => {
console.error('POST error:', error);
});
İstek Yönetimi
const req = client.get('https://api.example.com/data');
client.cancelRequest(req);
if (client.isRequestCancelled(req)) {
console.log('Request was cancelled');
} else {
console.log('Request is active');
}
client.retryRequest('GET', 'https://api.example.com/data', null, {}, 3)
.then(response => {
console.log('Retry successful:', response);
})
.catch(error => {
console.error('Retry failed:', error);
});
Dosya İşlemleri
client.downloadFile('https://example.com/file.zip', './downloads/file.zip')
.then(filePath => {
console.log('File downloaded:', filePath);
})
.catch(error => {
console.error('Download error:', error);
});
const filePath = './uploads/file.txt';
client.uploadFile('https://api.example.com/upload', filePath)
.then(response => {
console.log('File uploaded:', response);
})
.catch(error => {
console.error('Upload error:', error);
});
Akış İşlemleri
client.streamRequest('https://api.example.com/stream')
.then(stream => {
stream.on('data', data => {
console.log('Stream data:', data);
});
stream.on('end', () => {
console.log('Stream ended');
});
stream.on('error', error => {
console.error('Stream error:', error);
});
})
.catch(error => {
console.error('Stream request error:', error);
});
client.retryStreamRequest('https://api.example.com/stream')
.then(stream => {
// Akış üzerinde işlem yapma
})
.catch(error => {
console.error('Retry stream request error:', error);
});
Önbellek ve Sınırlama
client.cacheResponse('https://api.example.com/data', { data: 'cached' }, 60); // 60 saniye boyunca önbelleğe alınır
client.getCacheResponse('https://api.example.com/data')
.then(response => {
console.log('Cached response:', response);
})
.catch(error => {
console.error('Cache error:', error);
});
client.limitRequests('https://api.example.com/rate-limited', 100, 3600)
.then(() => {
console.log('Request limit applied successfully');
})
.catch(error => {
console.error('Request limit error:', error);
});