This Laravel package is a wrapper for the Prepr API.
Compatible with Laravel v5x, v6x, v7x, v8x.
You can install the package via composer:
composer require graphlr/prepr-api-laravel
PREPR_URL=https://api.eu1.prepr.io/
PREPR_TOKEN=ToKeN
PREPR_CACHE=true
PREPR_CACHE_TIME=1800
For all the requests
config(['prepr.url' => 'https://api.eu1.prepr.io/']);
config(['prepr.token' => 'ToKeN']);
The authorization can also be set for one specific request ->url('url')->authorization('token')
.
use Graphlr\Prepr\Prepr;
$apiRequest = (new Prepr)
->path('tags')
->query([
'fields' => 'example'
])
->get();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('tags/{id}',[
'id' => 1
]),
->query([
'fields' => 'example'
])
->get();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('tags')
->params([
'body' => 'Example'
])
->post();
if($apiRequest->getStatusCode() == 201) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('tags')
->params([
'body' => 'Example'
])
->put();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('tags/{id}',[
'id' => 1
])
->delete();
if($apiRequest->getStatusCode() == 204) {
// Deleted.
}
$apiRequest = (new Prepr)
->path('tags/{id}',[
'id' => 1
]),
->query([
'fields' => 'example'
])
->userId(session()->getId())
->get();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('assets')
->params([
'body' => 'Example',
])
->file('/path/to/file.txt') // For laravel storage: storage_path('app/file.ext')
->post();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
$apiRequest = (new Prepr)
->path('publications')
->query([
'limit' => 200 // optional
])
->autoPaging();
if($apiRequest->getStatusCode() == 200) {
dump($apiRequest->getResponse());
}
For debug you can use getRawResponse()
For all the details and full documentation check out the Prepr Developer docs