The API package is a universal RESTful API and has some resources available right out of the box.
Entries represent the data within your configured Streams. Use the Entries API to interact with streams data.
Entries represent the data within your configured Streams. Use the Entries API to interact with streams data.
In general, routing endpoints for the API is very similar to routing anything else in Laravel.
If you are using the ApiCache middleware you will want to make sure and include the stream
hint in your routes action.
// routes/api.php
Route::streams('examples/{id}/do-something', [
'stream' => 'examples',
'uses' => DoSomething::class
]);
You can define API in a number of different
The app/Providers/RouteServiceProvider.php
file typically uses the api
middleware group when loading the routes/api.php
file. By default this is compatible and routes defined there will be properly prefixed and grouped.
You may also route API endpoints using the router directly.
Route::prefix('api')
->middleware('api')
->group(function () {
// Define your routes.
});
When routing API endpoints from a package, the API prefix and middleware group is potentially unknown. You may use the API configuration to determine the correct values:
Route::prefix(Config::get('streams.api.prefix', 'api'))
->middleware(Config::get('streams.api.middleware', 'api'))
->group(function () {
// Define your routes.
});
You may use the ApiResponse
utility to return standardized JSON responses.
Responses will automatically include built-in links and meta and will default to a 200
status code.
// app\Controller\Api\DoSomething;
use Streams\Api\ApiResponse;
public function __invoke($id)
{
$response = new ApiResponse('examples');
// Your endpoint logic...
return $response->make();
}
Below is a list of methods you can use to configure the response:
$response->setStatus(int $status): self
$response->addHeader(string $name, mixed $value): self
$response->removeHeader(string $name): self
$response->addError(array $error): self
$response->addLink(string $name, mixed $value): self
$response->removeLink(string $name): self
$response->addMeta(string $name, mixed $value): self
$response->removeMeta(string $name): self
$response->setData(mixed $data): self
$response->make(mixed $data = null, int $status = null, array $headers = []): JsonResponse
A blank TALL-stack Laravel project with Streams.
The fundamental features and utilities offered by the Streams platform.
A universal and extensible RESTful API for Streams.
Extensible, user-friendly, and performant control panel, components, and services.
Dev tooling for Laravel Streams.