import { createUrlBuilder } from '@bytekit/utils';
class ApiClient {
private baseUrl = 'https://api.example.com';
async getUsers(page: number, limit: number, filters?: {
role?: string;
verified?: boolean;
}) {
const url = createUrlBuilder(this.baseUrl)
.path('/api/v1/users')
.query({
page,
limit,
...filters
})
.build();
const response = await fetch(url);
return response.json();
}
async searchPosts(query: string, tags: string[]) {
const url = createUrlBuilder(this.baseUrl)
.path('/api/v1/posts/search')
.query({ q: query })
.queryArray({ tags })
.build();
const response = await fetch(url);
return response.json();
}
}
const client = new ApiClient();
// Fetch users with filters
const users = await client.getUsers(1, 20, {
role: 'admin',
verified: true
});
// Search posts with multiple tags
const posts = await client.searchPosts('typescript', [
'tutorial',
'beginner'
]);