A simplified JavaScript client for interacting with the Laravel Streams API.
Version 3.0 - Rebuilt with native JavaScript. Zero runtime dependencies. Simple and maintainable.
✨ Zero Dependencies - Uses native fetch API
🎯 PHP Laravel-style Criteria - Familiar query builder interface
🔌 Middleware System - Extensible request/response pipeline
📦 Tiny Bundle - ~22KB CommonJS, ~21KB ESM
🧪 Fully Tested - 70 tests, 100% passing
⚡ Modern JS - ES6+ with both ESM and CommonJS builds
npm install @laravel-streams/api-clientimport { Client } from '@laravel-streams/api-client';
const client = new Client({
baseURL: 'http://localhost/api'
});
// Get all streams
const streams = await client.streams.get();
// Get entries from a stream
const entries = await client.entries.get('posts');
// Find a specific entry
const entry = await client.entries.find('posts', 1);
// Create an entry
const newEntry = await client.entries.post('posts', {
title: 'Hello World',
content: 'This is my first post'
});
// Update an entry
await client.entries.patch('posts', 1, {
title: 'Updated Title'
});
// Delete an entry
await client.entries.delete('posts', 1);- Installation - Installation and setup
- Quick Start - Get started quickly
- Client Configuration - Client initialization and configuration
- Working with Streams - Managing streams
- Working with Entries - CRUD operations for entries
- Criteria Query Builder - PHP Laravel-style querying
- Middleware - Request/response middleware
- Examples - Real-world usage examples
The Criteria class provides a fluent interface similar to Laravel's query builder:
import { Criteria } from '@laravel-streams/api-client';
const criteria = new Criteria()
.where('status', 'published')
.where('views', '>', 100)
.orderBy('created_at', 'desc')
.limit(10);
// Use with entries
const response = await client.entries.get('posts', {
criteria: criteria
});The client supports middleware for request/response processing:
import { Client, AuthorizationMiddleware } from '@laravel-streams/api-client';
const auth = new AuthorizationMiddleware({
token: 'your-api-token',
type: 'Bearer'
});
const client = new Client({
baseURL: 'http://localhost/api',
middlewares: [auth]
});client.streams.get()- Get all streamsclient.streams.find(stream)- Get a specific streamclient.entries.get(stream)- Get entries from a streamclient.entries.find(stream, id)- Find a specific entryclient.entries.post(stream, data)- Create an entryclient.entries.patch(stream, id, data)- Update an entryclient.entries.delete(stream, id)- Delete an entry
where(field, value)- Add a where clausewhere(field, operator, value)- Add a where clause with operatororWhere(field, value)- Add an OR where clauseorderBy(field, direction)- Order resultslimit(number)- Limit resultspaginate(perPage, page)- Paginate results
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Watch mode for tests
npm run test:watch
# Clean build artifacts
npm run cleanIf you're upgrading from version 2.x (TypeScript), see the Migration Guide for details on changes and how to upgrade.
Contributions are welcome! Please feel free to submit a Pull Request.
MIT