Features: - Zero configuration, just works out of the box - Runtime type inference and validation - Built-in caching with W-TinyLFU algorithm - Automatic retries with exponential backoff - Circuit breaker for resilience - Request deduplication - Offline support with queue - OpenAPI schema discovery - Full TypeScript support with type descriptors - Modular architecture - Configurable for advanced use cases Built with bun, ready for npm publishing
40 lines
No EOL
1 KiB
TypeScript
40 lines
No EOL
1 KiB
TypeScript
import { tf } from '../src/index.js'
|
|
|
|
// Basic GET request
|
|
async function basicExample() {
|
|
console.log('=== Basic GET Request ===')
|
|
const user = await tf.get('https://api.github.com/users/github')
|
|
console.log('User:', user.name)
|
|
console.log('Company:', user.company)
|
|
}
|
|
|
|
// POST request with data
|
|
async function postExample() {
|
|
console.log('\n=== POST Request ===')
|
|
const response = await tf.post('https://jsonplaceholder.typicode.com/posts', {
|
|
title: 'TypedFetch is awesome',
|
|
body: 'Zero dependencies, just works!',
|
|
userId: 1
|
|
})
|
|
console.log('Created post:', response)
|
|
}
|
|
|
|
// Error handling
|
|
async function errorExample() {
|
|
console.log('\n=== Error Handling ===')
|
|
try {
|
|
await tf.get('https://api.github.com/users/this-user-definitely-does-not-exist-404')
|
|
} catch (error) {
|
|
console.log('Caught error:', error.message)
|
|
console.log('Status:', error.status)
|
|
}
|
|
}
|
|
|
|
// Run examples
|
|
async function main() {
|
|
await basicExample()
|
|
await postExample()
|
|
await errorExample()
|
|
}
|
|
|
|
main().catch(console.error) |