preprio/laravel-rest-sdk is a Laravel package for laravel sdk for the prepr rest api..
It currently has 2 GitHub stars and 5.104 downloads on Packagist (latest version 4.2.2).
Install it with composer require preprio/laravel-rest-sdk.
Discover more Laravel packages by preprio
or browse all Laravel packages to compare alternatives.
Last updated
This Laravel package is a provider for the Prepr REST API.
v8x, v9x, v10x, v11x, v12x.GuzzleHttp 7.3.X, and for version 3.0 and above PHP 8.x is required.You can install the Provider as a composer package.
For Laravel v10x, v11x and Laravel v12x
composer require preprio/laravel-rest-sdk:"^4.0"
For Laravel v9x
composer require preprio/laravel-rest-sdk:"^2.0"
Publish prepr.php config
php artisan vendor:publish --provider="Preprio\PreprServiceProvider"
You can set the default configuration in your .env file of you Laravel project.
PREPR_URL=https://cdn.prepr.io/
PREPR_TOKEN={{ACCESS_TOKEN}}
To make use of the caching feature of Laravel, add the following parameters to your .env file.
PREPR_CACHE=true
PREPR_CACHE_TIME=1800
PREPR_TIMEOUT=30
PREPR_CONNECT_TIMEOUT=10
Let's start with getting all content items from your Prepr Environment.
<?php
use Preprio\Prepr;
$apiRequest = new Prepr;
$apiRequest
->path('publications')
->query([
'fields' => 'items'
])
->get();
if($apiRequest->getStatusCode() == 200) {
print_r($apiRequest->getResponse());
}
To get a single content item, pass the Id to the request.
<?php
use Preprio\Prepr;
$apiRequest = new Prepr;
$apiRequest
->path('publications/{id}', [
'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09'
])
->query([
'fields' => 'items'
])
->get();
if($apiRequest->getStatusCode() == 200) {
print_r($apiRequest->getResponse());
}
Use {param?} for optional route segments (similar to Laravel route syntax). When the value is null or the key is missing, the segment is omitted from the path. Required placeholders ({param}) log a warning when the value is missing or null, and the path is normalized (no trailing slashes).
An empty string ('') is treated as a provided value, not as missing.
$apiRequest = (new Prepr)
->path('tags/{id?}', [
'id' => $id,
])
->get();
The authorization can also be set for one specific request ->url('url')->authorization('token').
$apiRequest = (new Prepr)
->path('publications')
->query([
'limit' => 200 // optional
])
->autoPaging();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('publications')
->params([
'body' => 'Example'
])
->post();
if($apiRequest->getStatusCode() == 201) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('publications')
->params([
'body' => 'Example'
])
->put();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('publications')
->params([
'body' => 'Example'
])
->patch();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('publications/{id}',[
'id' => 1
])
->delete();
if($apiRequest->getStatusCode() == 204) {
// Deleted.
}
use Illuminate\Support\Facades\Storage;
$source = Storage::readStream('image.jpg');
$apiRequest = (new Prepr)
->path('assets')
->params([
'body' => 'Example',
])
->file($source);
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
use Illuminate\Support\Facades\Storage;
$source = Storage::get('image.jpg');
$apiRequest = (new Prepr)
->path('assets')
->params([
'body' => 'Example',
])
->file($source, 'image.jpg');
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
For debug you can use getRawResponse()