A powerful, flexible RESTful API package for the Laravel Streams platform. Get instant CRUD endpoints for all your streams with extensive customization options.
- π Automatic REST Endpoints - Instant CRUD operations for all streams
- π Advanced Querying - Filtering, pagination, and custom query methods
- π― Custom Interfaces - Multiple API configurations with different prefixes and middleware
- π οΈ Custom Endpoints - Easy to add your own routes and logic
- π Middleware Support - Authentication, rate limiting, and more
- π OpenAPI/Swagger - Auto-generate interactive API documentation
- β‘ Response Formatting - Standardized JSON responses
- πΎ HTTP Caching - Built-in caching with ETag support
composer require streams/api:1.0.x-devEnable the API in your .env:
STREAMS_API_ENABLED=trueRegister routes in your AppServiceProvider:
use Streams\Api\Support\Facades\API;
public function boot()
{
API::routeEntries(); // Entry CRUD endpoints
API::routeStreams(); // Stream management endpoints
}That's it! Your API is now available at /api.
π Full Documentation
- Introduction - Overview and quick start
- Configuration - Configure the API
- Query Parameters - Filter and paginate data
- Custom Interfaces - Multiple API configurations
- Custom Endpoints - Add your own routes
- Responses - Format API responses
- OpenAPI - Generate Swagger documentation
- Testing - Test your API
Note: Documentation URLs like /docs/api/introduction correspond to docs/introduction.md in this repository.
GET /api/streams # List all streams
POST /api/streams # Create a stream
GET /api/streams/{stream} # Get a stream
PUT /api/streams/{stream} # Update a stream
PATCH /api/streams/{stream} # Partially update a stream
DELETE /api/streams/{stream} # Delete a stream
GET /api/streams/{stream}/entries # List entries
POST /api/streams/{stream}/entries # Create an entry
GET /api/streams/{stream}/entries/{entry} # Get an entry
PUT /api/streams/{stream}/entries/{entry} # Update an entry
PATCH /api/streams/{stream}/entries/{entry} # Partially update an entry
DELETE /api/streams/{stream}/entries/{entry} # Delete an entry
POST /api/streams/{stream}/query # Advanced queries
GET /api/streams/posts/entries?where[status]=published&per_page=10&page=1POST /api/streams/posts/query
Content-Type: application/json
{
"parameters": [
{"where": ["status", "published"]},
{"where": ["views", ">", 100]},
{"orderBy": ["created_at", "desc"]},
{"limit": [20]}
]
}use Streams\Api\ApiInterface;
use Streams\Api\Support\Facades\API;
$api = new ApiInterface('v1');
$api->path('api/v1');
$api->middleware(['auth:sanctum', 'throttle:60,1']);
API::interface($api);
API::routeEntries();use Streams\Api\ApiResponse;
$api->endpoints([
'featured' => function () {
$posts = Streams::entries('posts')
->where('featured', true)
->get();
return ApiResponse::make($posts);
}
]);Publish configuration file:
php artisan vendor:publish --provider=Streams\\Api\\ApiServiceProvider --tag=config// config/streams/api.php
return [
'enabled' => env('STREAMS_API_ENABLED', false),
'prefix' => env('STREAMS_API_PREFIX', 'api'),
'middleware' => env('STREAMS_API_MIDDLEWARE', 'api'),
];Create OpenAPI schema:
php artisan api:schemaGenerate Swagger UI:
php artisan api:documentationVisit /docs/api/index.html to view interactive API documentation.
Run tests:
php vendor/bin/phpunitGenerate coverage report:
XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-html=./coverageCurrent test suite: 142 tests, 394 assertions β
// config/streams/api.php
'middleware' => ['api', 'auth:sanctum', 'throttle:60,1'],Or per-interface:
$api->middleware(['auth:sanctum']);- PHP 8.1+
- Laravel 10.0+
- Streams Core 1.0+
The Streams API is open-source software licensed under the MIT license.
- π Documentation
- π¬ Discussions
- π Issues
- π Website
- Gates based on Core/Laravel Gates for authorization
- API versioning helpers
- Rate limiting per endpoint
- API key authentication
- Webhook support
- GraphQL support
- Real-time subscriptions
- Batch operations
- API analytics/metrics