Welcome! This guide will help you get up and running with @pubflow/flowfull-client in just a few minutes.
Install the package using your favorite package manager:
# npm
npm install @pubflow/flowfull-client
# yarn
yarn add @pubflow/flowfull-client
# pnpm
pnpm add @pubflow/flowfull-client
# bun
bun add @pubflow/flowfull-clientThe simplest way to get started is with the createFlowfull factory function:
import { createFlowfull } from '@pubflow/flowfull-client';
// Create a client pointing to your Flowfull backend
const api = createFlowfull('https://api.myapp.com');That's it! You now have a fully functional HTTP client ready to use.
// Fetch all users
const response = await api.get('/users');
if (response.success) {
console.log('Users:', response.data);
} else {
console.error('Error:', response.error);
}const newUser = {
name: 'John Doe',
email: 'john@example.com',
age: 30
};
const response = await api.post('/users', newUser);
if (response.success) {
console.log('Created user:', response.data);
}const updates = {
name: 'John Updated'
};
const response = await api.put('/users/123', updates);const response = await api.patch('/users/123', {
status: 'active'
});const response = await api.delete('/users/123');The query builder makes it super easy to build complex queries with filters, pagination, and sorting:
const response = await api
.query('/products')
.where('status', 'active')
.where('price', 'gte', 50)
.sort('price', 'asc')
.page(1)
.limit(20)
.get();
console.log('Products:', response.data);
console.log('Pagination:', response.meta);If you're using Pubflow authentication, the client will automatically detect your session:
// Session is auto-detected from localStorage (pubflow_session_id)
const api = createFlowfull('https://api.myapp.com');
// All requests will include the session header automatically
const response = await api.get('/profile');You can also provide a session ID manually:
const api = createFlowfull('https://api.myapp.com', {
sessionId: 'your-session-id-here'
});For more complex scenarios, use a function:
const api = createFlowfull('https://api.myapp.com', {
getSessionId: () => {
// Get session from your auth system
return localStorage.getItem('my_session_key');
}
});All responses follow a consistent format:
interface ApiResponse<T> {
success: boolean; // Whether the request succeeded
data?: T; // Response data (if successful)
error?: string; // Error message (if failed)
message?: string; // Additional message
status: number; // HTTP status code
meta?: { // Pagination metadata (if applicable)
page?: number;
limit?: number;
total?: number;
totalPages?: number;
};
}const response = await api.get('/users');
// Always check success first
if (response.success) {
// TypeScript knows data is available
console.log('Users:', response.data);
// Check pagination
if (response.meta) {
console.log(`Page ${response.meta.page} of ${response.meta.totalPages}`);
}
} else {
// Handle error
console.error(`Error ${response.status}: ${response.error}`);
}Now that you know the basics, explore more advanced features:
- Filter Operators - Learn about all 14 filter operators
- Query Builder - Master the chainable query builder
- Configuration - Customize your client
- Error Handling - Handle errors like a pro
- TypeScript - Get the most out of TypeScript
const activeUsers = await api
.query('/users')
.where('status', 'active')
.where('verified', true)
.get();const page2 = await api
.query('/products')
.page(2)
.limit(25)
.get();const results = await api
.query('/products')
.search('laptop')
.get();- 📚 Check out the full documentation
- 💬 Join our Discord community
- 🐛 Report issues on GitHub
Happy coding! 🎉