@yurbajs/rest
v1.0.0-next.12
Published
REST client for Yurba API
Downloads
48
Readme
About
REST client for Yurba API with full TypeScript support.
WARNING: it's alpha version
Install
Node.js 20 or newer is required.
npm install @yurbajs/rest
yarn add @yurbajs/rest
pnpm add @yurbajs/rest
bun add @yurbajs/restExample usage
import { REST } from '@yurbajs/rest';
const api = new REST('TOKEN');
try {
// Get user info
const user = await api.users.me();
console.log('Bot user:', user);
// Send message
const message = await api.dialogs.sendMessage(292, {text: "hello world"})
console.log('Message: ', message)
// Batch requests for better performance
const results = await api.batch()
.add('user', api.users.get(1111))
.add('posts', api.posts.get('@me'))
.add('friends', api.users.friends())
.execute();
console.log('User:', results.user);
console.log('Posts:', results.posts);
console.log('Friends:', results.friends);
} catch (error) {
console.error('Failed to get data:', error.message);
}Batch Requests
Execute multiple API calls in parallel for better performance:
// Instead of sequential calls (slow)
const user = await api.users.me(); // 300ms
const posts = await api.posts.get('@me', {}); // 300ms
const friends = await api.users.friends(); // 300ms
// Total: ~900ms
// Use batch requests (fast)
const results = await api.batch()
.add('user', api.users.me())
.add('posts', api.posts.get('@me', {}))
.add('friends', api.users.friends())
.execute();
// Total: ~300ms (parallel)
// Handle partial failures
const results = await api.batch()
.add('user', api.users.me())
.add('invalid', api.users.get(-1)) // will fail
.executeSettled(); // won't throw on errors
console.log(results.user); // User object
console.log(results.invalid); // { error: Error }Links
Contributing
Want to help make yurba.js better?
- Found a bug? Open an issue.
- Have an idea? Start a discussion.
- Want to contribute code? Fork the repository and submit a pull request.
Please make sure to follow our coding style and test your changes before submitting.
Getting Help
Need assistance?
- Check the documentation first.
- Ask questions in our Chat.
- Browse existing issues and discussions.
