A tiny, dependency-free, axios-style fetch wrapper for Deno
- 🚀 Axios-style API - Familiar interface for HTTP requests
- 🎯 Zero Dependencies - Built on top of native Fetch API
- 📦 TypeScript First - Full type safety
- 🔄 Interceptors - Request, response, and error interceptors
- ⚙️ Configuration - Global and per-request configuration
- ⏱️ Timeout Support - Built-in request timeout handling
- 🎨 Multiple Response Types - JSON, text, blob, arrayBuffer
import { createClient } from 'jsr:@anitrend/request-client@^0.1.0';{
"imports": {
"@anitrend/request-client": "jsr:@anitrend/request-client@^0.1.0"
}
}Then import in your code:
import { createClient } from '@anitrend/request-client';This package is built for Deno and published via JSR (JavaScript Registry).
Fully supported with zero dependencies. Uses native Fetch API.
import { createClient } from 'jsr:@anitrend/request-client@^0.1.0';Compatible with Node.js 18+ through JSR's npm compatibility layer:
# Using npm
npx jsr add @anitrend/request-client
# Using yarn
yarn dlx jsr add @anitrend/request-client
# Using pnpm
pnpm dlx jsr add @anitrend/request-clientThen import in your Node.js code:
import { createClient } from '@anitrend/request-client';Compatible with Bun through JSR:
bunx jsr add @anitrend/request-clientAny JavaScript runtime that supports:
- Native Fetch API
- ES Modules
- TypeScript (optional)
Should work with this package. Compatibility may vary based on the runtime's Fetch API implementation.
import { createClient } from 'jsr:@anitrend/request-client';
// Create a client instance
const client = createClient();
// Make a GET request
const response = await client.get('https://api.example.com/users');
console.log(response.data);
// Make a POST request
const newUser = await client.post('https://api.example.com/users', {
name: 'John Doe',
email: '[email protected]',
});
console.log(newUser.data);import { createClient } from 'jsr:@anitrend/request-client';
const client = createClient({
baseURL: 'https://api.example.com',
headers: {
'Authorization': 'Bearer YOUR_TOKEN',
'Content-Type': 'application/json',
},
timeout: 5000, // 5 seconds
});
// Now all requests use the baseURL
const users = await client.get('/users');
const user = await client.get('/users/1');const response = await client.get('/search', {
params: {
q: 'deno',
limit: 10,
},
});
// Requests: /search?q=deno&limit=10client.interceptors.request.use((config) => {
// Modify request config before sending
config.headers = {
...config.headers,
'X-Custom-Header': 'value',
};
return config;
});client.interceptors.response.use((response) => {
// Transform response data
console.log('Response received:', response.status);
return response;
});import { RequestError } from 'jsr:@anitrend/request-client';
try {
const response = await client.get('/endpoint');
} catch (error) {
if (error instanceof RequestError) {
console.error('Status:', error.response?.status);
console.error('Data:', error.response?.data);
}
}const client = createClient(config?: RequestConfig);interface RequestConfig {
baseURL?: string;
headers?: Record<string, string>;
timeout?: number;
params?: Record<string, string | number | boolean>;
data?: unknown;
responseType?: 'json' | 'text' | 'blob' | 'arrayBuffer';
signal?: AbortSignal;
validateStatus?: (status: number) => boolean;
}// GET request
client.get<T>(url: string, config?: RequestConfig): Promise<RequestResponse<T>>
// POST request
client.post<T>(url: string, data?: unknown, config?: RequestConfig): Promise<RequestResponse<T>>
// PUT request
client.put<T>(url: string, data?: unknown, config?: RequestConfig): Promise<RequestResponse<T>>
// PATCH request
client.patch<T>(url: string, data?: unknown, config?: RequestConfig): Promise<RequestResponse<T>>
// DELETE request
client.delete<T>(url: string, config?: RequestConfig): Promise<RequestResponse<T>>
// HEAD request
client.head<T>(url: string, config?: RequestConfig): Promise<RequestResponse<T>>
// OPTIONS request
client.options<T>(url: string, config?: RequestConfig): Promise<RequestResponse<T>>interface RequestResponse<T = unknown> {
data: T;
status: number;
statusText: string;
headers: Headers;
config: RequestConfig;
}- Deno 2.x or higher
# Run unit tests
deno task test:unit
# Run specification tests
deno task test:spec
# Watch mode
deno task test:watch
# Generate coverage report
deno task coverage# Linting
deno task lint
# Formatting
deno task fmt
# Check formatting
deno task fmt:check
# Type checking
deno task checkContributions are welcome! Please read our Code of Conduct before contributing.
Copyright 2025 AniTrend
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.